简体   繁体   English

sql插入查询

[英]sql insert into query

Please help! 请帮忙!

What is wrong with this INSERT INTO query?! 此INSERT INTO查询有什么问题?

This is before the query on the newUser.php page 这是在newUser.php页面上进行查询之前

$result2=mysqli_query($con,"SELECT count(*) AS count FROM boards");
while($row2 = mysqli_fetch_array($result2)){
    $postNumber=$row2["count"];
}
echo $postNumber;
echo $_POST['bday'];

This is the query 这是查询

mysqli_query($con,"INSERT INTO users (userID, profPicLoc, age, username, realName, birthday, password, meBoardID, email) VALUES (0, 'aa', 17, '" . $_POST['username2'] . "', '" . $_POST['name'] . "', '" . $_POST['bday'] . "', '" . $_POST['password2'] . "', " . $postNumber+2 . ", '" . $_POST['email'] . "')";

The connection is made to the database correctly, the userID is auto increment, and the birthday field in the database is DATE type 正确建立了到数据库的连接,用户标识为自动递增,数据库中的生日字段为DATE类型

it recieves the information from this form on another page... 它从另一页上的此表单中接收信息。

<form action="newUser.php" method="post">
</br>Name: <input type="text" name="name"></input></br>
Username: @<input type="text" name="username2"></input></br>
Password: <input type="password" name="password2"></input></br>
Email: <input type="text" name="email"></input></br>
Birthday: <input type="date" name="bday"></br>
<input type="submit"></input>
</form>

mysqli_query() parenthesis closing is wrong. mysqli_query()括号关闭是错误的。 Need one more closing parenthesis at the end. 最后需要再加上一个右括号。 remove the user_id from inserting if it is AI 如果是AI,则从插入中删除user_id

mysqli_query($con,"INSERT INTO users (profPicLoc, age, username, realName, birthday, password, meBoardID, email) 
VALUES ('aa', 17, '" . $_POST['username2'] . "', '" . $_POST['name'] . "', '" . $_POST['bday'] . "', '" . $_POST['password2'] . "', " . $postNumber+2 . ", '" . $_POST['email'] . "')");

Use it: 用它:

mysqli_query($con,"INSERT INTO users (profPicLoc, age, username, realName, birthday, password, meBoardID, email) VALUES ('aa', 17, '" . $_POST['username2'] . "', '" . $_POST['name'] . "', '" . $_POST['bday'] . "', '" . $_POST['password2'] . "', " . $postNumber+2 . ", '" . $_POST['email'] . "')";

never include primary key with auto incremented column while inserting. 插入时,切勿在主键包含自动递增的列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM