Im using php to insert data into an access database. Right now if there is an apostraphe in the form data im getting this error
[microsoft][odbc microsoft access driver] syntax error (missing operator) in the query expression…
I know this is caused by an apostraphe and I have magicquotes gpc turned on in the ini file so i dont get why this is happening. My boss is breathing down my neck about this database error so does anyone know a way around this? Ive tried stripslashes() addslashes() and neither work.
Here is my code if that helps
<?php
//Establishes connection to the access database
require_once('../../connect.php');
//Check to see if the form was submitted correctly
if(isset($_POST['Submit'])) { //check if form was submitted
//create an empty variable to store potential error messages.
$message = NULL;
//Check to see if Description was entered
if (empty($_POST['Description'])){
$d = FALSE;
$message .= '<p>Your forgot to enter the description</p>';
}else{
$d = $_POST['Description'];
}
//Check to see if benefits were entered
if (empty($_POST['Benefits'])){
$b = FALSE;
$message .= '<p>You forgot to enter the benefits</p>';
}else{
$b = $_POST['Benefits'];
}
//Check to see if Other was entered
if (empty($_POST['Other'])){
$o = 'User did not enter';
}else{
$o = $_POST['Other'];
}
//Check to see if Name was entered
if (empty($_POST['Name'])){
$n = 'User did not enter';
$message .= '<p>You forgot to enter your name</p>';
}else{
$n = $_POST['Name'];
}
if(isset($message)){
echo $message;
}else{
//Check for description and benefits and then run query to insert the data into access database.
if($d && $b){
//Run insert Query
$query = "INSERT INTO suggestions(name, idea, benefits, other)
VALUES ('$n', '$d', '$b', '$o')";
$result = odbc_exec($odbc, $query) or die (odbc_errormsg());
//check if query ran OK and then print confirmation message to user.
if($result){
echo 'Your suggestion has been submitted<br /><br /><a href=View.php>View Your Suggestion</a>';
}else{
echo'System error, if the problem persists please contact the help desk at 2610';
}
}
}
}
//closes connection to the access database.
odbc_close($odbc);
?>
Thanks in advance
SR