0

I have a simple database(test) with the table users; Under users I have columns user,idNum, password. When creating a registration form to add a new user I encounter an error that the username being set is the column it is looking for.

$conn = mysqli_connect("localhost", "root", ' ', "test");
$query = "INSERT INTO users (user, idNum, password) VALUES($user, &id, $password)";
$result = mysqli_query($conn,$query);

The result variable is always false and get I the column error for whatever the name I put into the username field in my HTML form.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
Bryce
  • 97
  • 1
  • 10

2 Answers2

1

You'll need single quotes around your variables, also, I think you typed &id instead of $id:

$query = "INSERT INTO users (user, idNum, password) VALUES('$user', '$id', '$password')";
Panda
  • 6,955
  • 6
  • 40
  • 55
0

There is nothing more than mistyping just replace & with $ before id, and it will work, I mean the correct code will look like as,

 $query = "INSERT INTO users (user, idNum, password) VALUES('$user', '$id', '$password')";
SKG
  • 540
  • 1
  • 5
  • 17
  • Yeah ! That solved your problem, please upvote the answer too, so as to motivate me for providing such answers to the community – SKG Mar 15 '16 at 15:01