Jump to content

[SOLVED] Help with writing data to a table


matthew798

Recommended Posts

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.. ;) )

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.