0

因此,在数据库中进行了简单的注册,但是First Nameand的值得到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();

?>
4

3 回答 3

1

尝试

name="Lname"

不是

name"Lname"

在您的 html 表单中

于 2013-06-05T21:17:53.737 回答
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">
于 2013-06-05T21:18:13.623 回答
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">
于 2013-06-05T21:19:11.557 回答