I'm practicing inserting data into Mysql with PHP on my localhost. As long as I do not include apostrophes, or if I add the backslashes to where I need apostrophes I am fine.
I'd like to add apostrophes at will, without the need for backslashes.
here is my code that inserts the data from my form into the database:
<?
//check for required fields
if ((!$POST[format]) || (!$POST[title])) {
header("Location: /show_addrecord.php");
exit;
}
//set up database and table names
$db_name ="my_music";
$table_name ="music";
//connect to MySQL and select database to use
$connection = @mysql_connect("localhost","root","") or die(mysql_error());
$db = @mysql_select_db($db_name,$connection) or die(mysql_error());
//create SQL statement and issue query
$sql = "INSERT INTO $table_name (format, title, artist_fn, artist_ln, rec_label, my_notes, date_acq) VALUES ('$POST[format]', '$POST[title]', '$POST[artist_fn]', '$POST[artist_ln]', '$POST[rec_label]', '$POST[my_notes]', '$_POST[date_acq]')";
$result = @($sql,$connection)or die(mysql_error());
?>
If I include apostrophes I get this error:
You have an error in your SQL syntax near 's .........
help!
Marc