I'm having an issue with SQL. I have tried all of the fixes I have found and nothing works.
This is the error I'm getting upon submission of the form:
**Error: 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 'a')' at line 2**
It's referencing the value of the field sent from the text field name="entity_name"
To test my fixes for the other fields I entered text with apostrophes randomly placed in every text field.
Everything works except for the first text field. Whereas before the error would have shown the syntax issue for all text fields and areas.
I have commented out $member = str_replace("'", "'", $member);
and
And have also commented out $member = mysql_real_escape_string($member);
Neither of them fixed the issue but neither is $member = addslashes($member);
Can someone help me figure out why there is still an SQL syntax issue when in reality there shouldn't be? Any help I can get would be greatly appreciated.
Here is my code:
<?php
session_start();
$con = mysql_connect("localhost","*******","*********");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("***********", $con);
$memberlinksafe = $_POST['entity_name'];
function strip_punctuation($memberlinksafe) {
$memberlinksafe = strtolower($memberlinksafe);
$memberlinksafe = preg_replace("/[:punct:]+/", "", $memberlinksafe);
$memberlinksafe = str_replace(" +", "", $memberlinksafe);
return $memberlinksafe;
}
//builds data from logo image to store into database
$logofile = $_FILES['cover_photo']['tmp_name'];
$logo = addslashes(file_get_contents($_FILES['cover_photo']['tmp_name']));
$logo_name = addslashes($_FILES['cover_photo']['tmp_name']);
//build data from cover photo image to store into database
$cover_photo_file = $_FILES['cover_photo']['tmp_name'];
$cover_photo = addslashes(file_get_contents($_FILES['cover_photo']['tmp_name']));
$cover_photo_name = addslashes($_FILES['cover_photo']['tmp_name']);
//build data from search photo image to store into database
$search_image_file = $_FILES['cover_photo']['tmp_name'];
$search_image = addslashes(file_get_contents($_FILES['cover_photo']['tmp_name']));
$search_image_name = addslashes($_FILES['cover_photo']['tmp_name']);
$member = $_POST['member'];
$member = addslashes($member);
//$member = str_replace("'", "'", $member);
//$member = mysql_real_escape_string($member);
//$entity_name = $_POST[entity_name];
//$entity_name = addslashes($entity_name);
//$entity_name = str_replace("'", "'", $entity_name);
$keywords = $_POST['keywords'];
$keywords = addslashes($keywords);
$street_address = $_POST['street_address'];
$street_address = addslashes($street_address);
$city = $_POST['city'];
$city = addslashes($city);
$st = $_POST['st'];
$st = addslashes($st);
$mailcode = $_POST['mailcode'];
$mailcode = addslashes($mailcode);
$website = $_POST['website'];
$website = addslashes($website);
$fb_url = $_POST['fb_url'];
$fb_url = addslashes($fb_url);
$hours = $_POST['hours'];
$hours = addslashes($hours);
$ph_number = $_POST['ph_number'];
$ph_number = addslashes($ph_number);
$body_header = $_POST['body_header'];
$body_header = addslashes($body_header);
//$body_header = str_replace("'", "'", $body_header);
$body_text = $_POST['body_text'];
$body_text = str_replace("'", "'", $body_text);
$search_blurb = $_POST['search_blurb'];
$search_blurb = str_replace("'", "'", $search_blurb);
$sql="INSERT INTO *********** (entity_name, category, keywords, street_address, community_id, city, st, country, mailcode, website, fb_url, email, hours, ph_number, body_header, body_text, search_blurb, dd, ad, ed, gd, md, vd, pd, logo, logofilename, cover_photo, coverphotofilename, search_image, searchimagefilename, memberlinksafe)
VALUES ('$member','$_POST[category]','$keywords','$street_address','$_POST[community_id]','$city','$st','$_POST[country]','$mailcode','$website','$fb_url','$_POST[email]','$hours','$ph_number','$body_header','$body_text','$search_blurb','$_POST[dd]','$_POST[ad]','$_POST[ed]','$_POST[gd]','$_POST[md]','$_POST[vd]','$_POST[pd]','$logo','$logo_name','$cover_photo','$cover_photo_name','$search_image','$search_image_name','$memberlinksafe')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "<h1>Thank you for submitting your details!</h1><br><p><a href='business-attraction.php'>Add another</a> business/attraction.</p>";
mysql_close($con);
?>