I have the following insert method:
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
foreach ($_POST['Category'] as $value){
$Full_Description = $_POST['Full_Description'];
$Specification = $_POST['Specification'];
$BriefDescription = $_POST['BriefDescription'];
$MPN = $_POST['MPN'];
$GTIN = $_POST['GTIN'];
$Product = $_POST['Product'];
$Color = $_POST['Color'];
$Model = $_POST['Model'];
$Manufacturer = $_POST['Manufacturer'];
$Category = $_POST['Category'];
$submitted = $_POST['submit'];
$insertSQL = sprintf("INSERT INTO products (Category, Manufacturer, Model, Color, Product, GTIN, MPN, BriefDescription, Specification, Full_Description) VALUES ('$value', '$Manufacturer','$Model','$Color','$Product','$GTIN','$MPN','$BriefDescription','$Specification','$Full_Description')",
GetSQLValueString($_POST['Category'], "text"),
GetSQLValueString($_POST['Manufacturer'], "text"),
GetSQLValueString($_POST['Model'], "text"),
GetSQLValueString($_POST['Color'], "text"),
GetSQLValueString($_POST['Product'], "text"),
GetSQLValueString($_POST['GTIN'], "text"),
GetSQLValueString($_POST['MPN'], "text"),
GetSQLValueString($_POST['BriefDescription'], "text"),
GetSQLValueString($_POST['Specification'], "text"),
GetSQLValueString($_POST['Full_Description'], "text");
mysql_select_db($database_dconn, $dconn);
$Result1 = mysql_query($insertSQL, $dconn) or die(mysql_error());
}}
The database field is: Full_Description longtext
Inserting data is working fine until the Full_Description contains a "'s". the error that comes up is:
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
I do not know why. Is there anybody who can help? I am very sorry if it is obvious, however I am really struggling Any help welcome