Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

escaping single quotes ' 1

Status
Not open for further replies.

farley99

MIS
Joined
Feb 12, 2003
Messages
413
Location
US
I had a guy fill this out with the name O' Brian, and got this error, it works ok with OBrian but the single quote breaks it, how do i fix this.


Secure Online Order Form
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 '1','1','','YES','','','','US','',
 
Help I still get htat error...

$querySTR="INSERT INTO......";
$query = mysql_escape_string($querySTR);
if(mysql_query($query))
echo " ";
else
echo mysql_error();
echo "\n";

Is that the right syntax?

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 's','joe','joe's','jk','j','j','j','j','JM','jj','j','j

 
The reason I am asking is because I don't believe you can use it against the entire query. mysql_escape_string() will probably escape the single quotes that should exist around strings to be inserted.

The way I use mysql_escape_string() is:

$username = "Brian O'Reilly";
$query = "INSERT INTO USERS set username = '" . mysql_escape_string($username) . "'";
mysql_query($query);
.
.
.

Want the best answers? Ask the best questions: TANSTAAFL!
 
You should first know which column will have insertion content with '. Like
if $name = "O'Brian"
you use $name = mysql_escape_string($name),
then you do "insert
values ('$name'...)
it will work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top