因此,在数据库中进行了简单的注册,但是First Name
and的值得到Last Name
了意外的索引,但帐户类型username
很好。
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 代码我已经在数据库中尝试过 issetvarFirstName
并且varLastName
仍然没有值。
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();
?>