因此做一個簡單的數據庫註冊,但值First Name
和Last 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代碼,我試圖在數據庫中的varFirstName
和varLastName
仍然沒有價值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();
?>
到底是什麼你得到的錯誤,並在該行? – scrblnrd3
$ varFirstName = isset($ _ POST ['Fname'])的意外指數? $ _POST [ 'FNAME']: ''; $ varLastName = isset($ _ POST ['Lname'])? $ _POST [ 'L-NAME']: ''; – patgarci
你在bind_param中的「sssss」是什麼意思? – pvnarula