matthew798 Posted August 29, 2008 Share Posted August 29, 2008 Hey guy! I'm new here and have been cracking down on a PHP tutorial ALL day. I've gotten as far as creating and managing tables and now i'm trying to get a script to write some user-entered values into that table. <?php $username = $_POST['username']; $password = $_POST['password']; $email = $_POST['email']; $country = $_POST['country']; $province = $_POST['province']; mysql_connect("localhost", "****", "****") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); mysql_query("INSERT INTO users (username, password, email, country, province) VALUES($username, $password, $email, $country, $province) ") or die(mysql_error()); echo "new user created successfully!"; ?> I starred out the user and pass because i'm completely paranoid.] Basically i'd like to know why i keep getting this message: "Unknown column 'aaa' in 'field list'" (i typed aaa in the username field for testing purposes) Here is what my table looks like: http://img527.imageshack.us/img527/4107/tablefw3.png if you guys need more info or other bits of my script (i'm near 110% sure the error is contained in the above script but i have been wrong a couple of times in my life.. ) Link to comment https://forums.phpfreaks.com/topic/121799-solved-help-with-writing-data-to-a-table/ Share on other sites More sharing options...
pocobueno1388 Posted August 29, 2008 Share Posted August 29, 2008 You need to put single quotes around all the variables in your insert query. mysql_query("INSERT INTO users (username, password, email, country, province) VALUES('$username', '$password', '$email', '$country', '$province') ") or die(mysql_error()); Also, you need to be using mysql_real_escape_string() on all your variables. Link to comment https://forums.phpfreaks.com/topic/121799-solved-help-with-writing-data-to-a-table/#findComment-628396 Share on other sites More sharing options...
matthew798 Posted August 29, 2008 Author Share Posted August 29, 2008 Thanks a bill! It worked with only the single quotes!!! I can't believe i made such a stupid mistake! Link to comment https://forums.phpfreaks.com/topic/121799-solved-help-with-writing-data-to-a-table/#findComment-628400 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.