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.

4
  • use mysqli not mysql. learn form other tutorial that teaches mysqli Commented Sep 1, 2013 at 3:07
  • Even if you just want your code to work, you could accidentally be SQL-injecting yourself and breaking your code. Try referring to stackoverflow.com/questions/60174/… Commented Sep 1, 2013 at 3:09
  • Make sure you are passing in the connection variable that you get back from mysqli_connect(...) Commented Sep 1, 2013 at 3:13
  • Like @dachi said, mysql_* functions are deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used. Commented Sep 1, 2013 at 4:01

1 Answer 1

2

php uses . to connect strings not +

and all the comments from Dachi and Mister Melancholy apply!

Sign up to request clarification or add additional context in comments.

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.