2013-06-05 55 views
0

因此做一個簡單的數據庫註冊,但值First NameLast Name是越來越意想不到的索引,但帳戶類型username是好的。PHP形式的兩個變量的意外索引

HTML代碼:

<form method="post" enctype="multipart/form-data" action="signIn.php"> 

     <h3>Create Your Account</h3> 


      Account Type 
      <select name="accountType"> 
        <option>Rentors</option> 
        <option>Homeowners</option> 
      </select> 

      First Name:     
      <input type="text" name"Fname" size="40"> 

      Last Name: 
      <input type="text" name"Lname" size="40"> 

      User Name: 
      <input type="text" name="username" size="40"> 

      Password: 
      <input type="password" name="password" size="40"> 


      <input type="submit" name="signInformSubmit" value="SIGN UP"> 

     </form> 

PHP代碼,我試圖在數據庫中的varFirstNamevarLastName仍然沒有價值isset。

if (isset($_POST['signInformSubmit'])) 
{ 
    $varAccountType = $_POST['accountType']; 
    $varFirstName = isset($_POST['Fname']) ? $_POST['Fname']:''; 
    $varLastName = isset($_POST['Lname']) ? $_POST['Lname']:''; 
    $varUserName = $_POST['username']; 
    $varPassword = $_POST['password']; 

} 

/////////////////////連接並插入數據庫///////////////// //

$mysqli = new mysqli("localhost","root","", "test"); 
if ($mysqli->connect_errno) { 
    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; 
} 

/* Prepared statement, stage 1: prepare */ 
$stmt = $mysqli->prepare("INSERT INTO accounts (accountType, FirstName, LastName, UserName, Password) VALUES (?,?,?,?,?)"); 
      /* Prepared statement, stage 2: bind and execute */ 
$stmt->bind_param('sssss', $varAccountType, $varFirstName, $varLastName, $varUserName, $varPassword); 



$stmt->execute(); 

    /* explicit close recommended */ 
$stmt->close(); 

$mysqli->close(); 

?> 
+0

到底是什麼你得到的錯誤,並在該行? – scrblnrd3

+0

$ varFirstName = isset($ _ POST ['Fname'])的意外指數? $ _POST [ 'FNAME']: ''; $ varLastName = isset($ _ POST ['Lname'])? $ _POST [ 'L-NAME']: ''; – patgarci

+0

你在bind_param中的「sssss」是什麼意思? – pvnarula

回答

1

嘗試

name="Lname" 

name"Lname" 

在HTML表單

+0

他也應該確保他爲每個表單字段定義了默認值,並且只有在所有必填字段完成時才插入到數據庫中。 –

+0

哇完全錯過,謝謝!! – patgarci

+1

哈哈我2!偉大的眼睛,史蒂文,user4035和scrblnrd3 –

0

你在你的HTML語法有一個錯誤:

<input type="text" name"Fname" size="40"> 

Last Name: 
<input type="text" name"Lname" size="40"> 

把 '=' 名稱後:

<input type="text" name="Fname" size="40"> 

Last Name: 
<input type="text" name="Lname" size="40"> 
0

你的HTML是關閉的。你永遠設置什麼

<input type="text" name"Fname" size="40"> 

     Last Name: 
     <input type="text" name"Lname" size="40"> 

應該

<input type="text" name="Fname" size="40"> 

     Last Name: 
     <input type="text" name="Lname" size="40">