为什么此代码插入空白?

时间:2016-07-12 20:10:26

标签: php html mysql database

我正在尝试创建一个连接到数据库的表单但是当我填写表单并且我在phpMyAdmin中引用表时,我看到它已经输入了空白记录而不是表单数据。我正在使用PhpStorm。

我认为所有这些代码都是正确的......

这是.html的形式:

<form id="form1" name="form1" method="post" action="index.php">
   <label for="userSignUp">Email</label>
   <input type="text" name="userSign" id="userSignUp" />
   <label for="passwordSignUp">Password</label>
   <input type="password" name="passwordSign" id="passwordSignUp" />
   <input type="submit" name="Submit" id="Submit" value="Submit" />
</form>

我有以下.php:

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$db_selected = mysqli_select_db($conn, $dbname);

$userSignUp = ""; // If I substitute "" with characters at this time the table is well updated
$passwordSignUp = ""; // Same as before

if(isset($_POST['userSign'])){
    $userSignUp = $_POST['userSign'];
}
if (isset($_POST['passwordSign'])) {
    $passwordSignUp = $_POST['passwordSign'];
}

$sql = "INSERT INTO test.person (FirstName, Password) VALUES ('$userSignUp', '$passwordSignUp')";

if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();

0 个答案:

没有答案