Apostrophe causing problems in insert to database

I have a particular field in a form that has an apostrphe in the title and when inserting into the database, I get the error relating to the apostrophe

So I tried the code below, and its not working, could somebody take a look please.

$sql = mysql_query("INSERT INTO hazzard (name_db, project_db, company_db, contact_db, detail_db, Location_1, Location_2, Location_3) VALUES ('{$_SESSION['name_A']}','{$_SESSION['projects_A']}','{$_SESSION['companies_A']}','{$_SESSION['numbers_A']}','$detail','".mysql_real_escape_string{$_SESSION['top_A']}."','{$_SESSION['middle_A']}','{$_SESSION['bottom_A']}')") or die (mysql_error());

Its where I am attempting to use mysql_real_escape_string

This is the error I’m getting -

Notice: Use of undefined constant mysql_real_escape_string - assumed ‘mysql_real_escape_string’ in E:\domains\a\page4.php on line 16
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 Building/Welcome Centre’,‘Level 4’,‘Riser’)’ at line 1

the following:


Should be


Ahh, thanks cpradio…

The funny thing is at first I couldnt see the difference, but thanks again.

Yeah, that is a bit hard to distinguish, isn’t it. :slight_smile: