Jump to content

php apostrophe help


NathanS

Recommended Posts

Hi there,

 

I'm having issues where people are inserting last names such as "O'Connor" and it's not writing to the database correctly:

 

$sql = "INSERT INTO customerav (TITLE, LNAME, PCODE) VALUES ('".$_POST["TITLE"]."', '.$_POST["LNAME"]."', '".$_POST["PCODE"]."')";

 

How would I best go about removing the apostrophe?

 

Cheers.

Link to comment
https://forums.phpfreaks.com/topic/95383-php-apostrophe-help/
Share on other sites

this is known as mysql injection...

 

wrap all your $_POST[] variables in mysql_escape_string()

 

eg:

 

$sql = "INSERT INTO customerav (TITLE, LNAME, PCODE) VALUES ('".mysql_escape_string($_POST["TITLE"])."', '.mysql_escape_string($_POST["LNAME"])."', '".mysql_escape_string($_POST["PCODE"])."')";

 

-- make sure you are connected to the db before using any mysql_escape_string functions

Link to comment
https://forums.phpfreaks.com/topic/95383-php-apostrophe-help/#findComment-488481
Share on other sites

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.