Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
-
Derek_24ca
- Forum Newbie
- Posts: 4
- Joined: Thu Oct 02, 2003 5:34 pm
-
Contact:
Post
by Derek_24ca »
Hello. Can someone take a look at this code for me?
Code: Select all
mysql_query("INSERT INTO table (email) values ($email)");
For some reason, $email dosen't get inserted into the mysql database. $email do contain a value from a form. Is this the right syntax?
Thanks.
-
scorphus
- Forum Regular
- Posts: 589
- Joined: Fri May 09, 2003 11:53 pm
- Location: Belo Horizonte, Brazil
-
Contact:
Post
by scorphus »
Change the code to:
Code: Select all
$query = "INSERT INTO table (email) values ($email)";
mysql_query($query) or die('Error: ' . mysql_error() . '<br>Query: ' . $query);
and try to find out what is wrong by yourself.
-- Scorphus
-
John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
-
Contact:
Post
by John Cartwright »
Should always quote your variable names too..
Code: Select all
mysql_query("INSERT INTO `table` (`email`) values ('$email')") or die(mysql_erorr());
Last edited by
John Cartwright on Wed Mar 02, 2005 1:51 pm, edited 1 time in total.
-
scorphus
- Forum Regular
- Posts: 589
- Joined: Fri May 09, 2003 11:53 pm
- Location: Belo Horizonte, Brazil
-
Contact:
Post
by scorphus »
...that's what I wanted him to find out...