MySQL insert failing because why

I am doing a mysql insert however it is failing when i enter data that contains apostrophe or a comma (ie. John Doe's Company)

The field is set to VarChar (50)

Here is my insert code.

What is the correct syntax to perform an insert when entering non standard characters?


$sql = "INSERT into doctors (trade_name) VALUES ('$trade_name')";
$result = mysql_db_query($dbname, $sql) or die("Failed Query of " . $sql);  //do the query

Open in new window

LVL 1
pdheadyAsked:
Who is Participating?
 
nplibConnect With a Mentor Commented:
$sql = "INSERT into doctors (trade_name) VALUES ('".mysql_escape_string($trade_name)."')";
$result = mysql_db_query($dbname, $sql) or die("Failed Query of " . $sql);  //do the query
0
 
pdheadyAuthor Commented:
thanks that works.
0
All Courses

From novice to tech pro — start learning today.