Please help!
What is wrong with this INSERT INTO query?!
This is before the query on the newUser.php page
$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
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. Need one more closing parenthesis at the end. remove the user_id
from inserting if it is AI
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.