Jump to content

Recommended Posts

hi!

 

this is my first post here, but it won't be my last.

 

i'm working on something simple...inserting data from a POST into a new mysql table row. i get the error "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@emailaddresshere" followed by the rest of the data to be inserted. the column type for the email address is char with a length 50. the query is:

 

$query = "INSERT INTO users_editors (fname, lname, email, phone1, phone2, hyear, cmail) VALUES($fname,$lname,$email,$phone1,$phone2,$hyear,$cmail)";

 

mysql_query($query) or die(mysql_error());

 

when i eliminate that variable, it then gives me the same error, but up to where there is a space in the data. it sounds like i'm not doing something needed to process the input before it goes into the table, but @ and spaces aren't escapable characters that i could find. help!

 

thanks!

 

lief

Add quotes in the values

 

$query = "INSERT INTO users_editors (fname, lname, email, phone1, phone2, hyear, cmail) VALUES('$fname','$lname','$email','$phone1','$phone2','$hyear','$cmail')";

 

mysql_query($query) or die(mysql_error());

 

P.S also remember to escape all data ( addslashes() ), else we'll be walking in circles :)

Add quotes in the values

 

$query = "INSERT INTO users_editors (fname, lname, email, phone1, phone2, hyear, cmail) VALUES('$fname','$lname','$email','$phone1','$phone2','$hyear','$cmail')";

 

mysql_query($query) or die(mysql_error());

 

P.S also remember to escape all data ( addslashes() ), else we'll be walking in circles :)

 

Actually, you'll want mysql_real_escape_string, not addslashes().

Add quotes in the values

 

$query = "INSERT INTO users_editors (fname, lname, email, phone1, phone2, hyear, cmail) VALUES('$fname','$lname','$email','$phone1','$phone2','$hyear','$cmail')";

 

mysql_query($query) or die(mysql_error());

 

P.S also remember to escape all data ( addslashes() ), else we'll be walking in circles :)

 

Actually, you'll want mysql_real_escape_string, not addslashes().

 

That doesn't really matter. The primary concern with SQL injection is the quotes. Therefore, if you do not care about line breaks and such then you will have no problem whatsoever with using addslashes() instead.

 

If you take a look ad addslashes()'s manual entry, then you will see that is says:

An example use of addslashes() is when you're entering data into a database.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.