Reputation: 112
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>
Upvotes: 0
Views: 137
Reputation: 313
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'] . "')");
Upvotes: 2
Reputation: 488
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.
Upvotes: 1