0

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>
5
  • 1
    "the userID is auto increment" - Then get rid of userID in your query. Commented Jul 25, 2014 at 4:20
  • 1
    don't build SQL queries with strings; it lets people hack you pretty easily. use bound parameters. Commented Jul 25, 2014 at 4:21
  • Fred, I already tried removing the userID field, still didn't work... I think it it a small syntax error but I have no idea what is going wrong Commented Jul 25, 2014 at 4:23
  • WOOOOOOOOW I'm stupid, I forgot the parentheses before the semi colon Commented Jul 25, 2014 at 4:34
  • Yeah, you have syntax error. Missing ) at the end before semi colon. Commented Jul 25, 2014 at 4:36

2 Answers 2

2

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'] . "')");
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.