0

I'm new to php and have been going through tutorials, and have hit a stump, where I can't seem to find what I'm doing wrong in my code, I welcome any and all assist, the code below is meant to insert data previously collected into a table that has those fields outline, in phpmyadmin:

$SQL = "INSERT INTO users ( 'username', 'password', 'email_address', 'date_of_birth', 'first_name', 'last_name', 'phone', 'address', 'city', 'userlevel') values ('" + $username + "', '" + $password + "', '" + $email_address + "', '" + $date_of_birth + "', '" + $first_name + "',  '" + $last_name + "', '" + $phone + "', '" + $address + "', '" + $city + "',  '" + $userlevel + "')";

And then to run that code:

 mysql_query($SQL); mysql_close($db_handle); print "Records added to the database";

I'm not 100% sure whether its the layout or not, for inserting variable data into MySql, also their is no errors about connecting to the database, furthermore the print at the end of the function runs, therefore it is not getting an error and stopping before running the code above.

Once again thank you and all assistance is welcome.

  • use `mysqli` not `mysql`. learn form other tutorial that teaches `mysqli` – Davit Sep 01 '13 at 03:07
  • Even if you just want your code to work, you could accidentally be SQL-injecting yourself and breaking your code. Try referring to http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php?rq=1 –  Sep 01 '13 at 03:09
  • Make sure you are passing in the connection variable that you get back from `mysqli_connect(...)` – brenjt Sep 01 '13 at 03:13
  • Like @dachi said, `mysql_*` functions are deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the [MySQLi](http://www.php.net/manual/en/book.mysqli.php) or [PDO_MySQL](http://www.php.net/manual/en/ref.pdo-mysql.php) extension should be used. – Fabien TheSolution Sep 01 '13 at 04:01

1 Answers1

2

php uses . to connect strings not +

and all the comments from Dachi and Mister Melancholy apply!

Rufinus
  • 29,200
  • 6
  • 68
  • 84