SQL query problem with $email variable

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
rsbeaulieu
Forum Newbie
Posts: 6
Joined: Tue Jul 02, 2002 6:02 am
Location: NH

SQL query problem with $email variable

Post by rsbeaulieu »

$result = mysql_query("INSERT INTO contestlist SET Email=" . $Email);

Error performing query: You have an error in your SQL syntax near '@hotmail.com' at line 1
8O
This is by the way a shortened version, i did that so i could change things to see if they worked and well this is as close as i ever got.

Well obviusly SQL queries do not like the '@' symbol. :?
I hear admitting the problems we have is half the battle :)
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Non numeric values should be enclosed in single quotes in your SQL query so:

Code: Select all

$sql = "INSERT INTO contestlist SET Email=".$Email;
should be

Code: Select all

$sql = "INSERT INTO contestlist SET Email='$Email'";
(There's no need to do concenation because the string is enclosed by double quotes.)

Mac
rsbeaulieu
Forum Newbie
Posts: 6
Joined: Tue Jul 02, 2002 6:02 am
Location: NH

Post by rsbeaulieu »

Oh thank you, thank you thank you thank you thank you, ive rewritten that code so many ways i probably could of impressed u with my imagination.
It works and im again im thankful. :D
Post Reply