Hi I am very new to PHP so this is probably a silly question.
I am running apache version 2, php 5, MySQL 5 and dreamweaver MX 6.1
I have tested all of the above which work together fine. I have now created a connection in dreamwear to MySQL which works, but I have just used dreamweaver wizard to create a form for inserting into a database. but get the following 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 '' at line 1
Here is the code.
<?php require_once('Connections/TestConn.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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($POST["MM_insert"])) && ($POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO customers (CustomerName, TradingName, Address#1, Address#2, Town, County, PostCode, Telephone, FaxNo) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($POST['CustomerName'], "text"),
GetSQLValueString($POST['TradingName'], "text"),
GetSQLValueString($POST['Address1'], "text"),
GetSQLValueString($POST['Address2'], "text"),
GetSQLValueString($POST['Town'], "text"),
GetSQLValueString($POST['County'], "text"),
GetSQLValueString($POST['PostCode'], "text"),
GetSQLValueString($POST['Telephone'], "text"),
GetSQLValueString($_POST['FaxNo'], "text"));
echo($insertSQL);
mysql_select_db($database_TestConn, $TestConn);
$Result1 = mysql_query($insertSQL, $TestConn) or die(mysql_error());
$insertGoTo = "index.html";
if (isset($SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">CustomerName:</td>
<td><input type="text" name="CustomerName" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">TradingName:</td>
<td><input type="text" name="TradingName" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Address#1:</td>
<td><input type="text" name="Address1" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Address#2:</td>
<td><input type="text" name="Address2" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Town:</td>
<td><input type="text" name="Town" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">County:</td>
<td><input type="text" name="County" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">PostCode:</td>
<td><input type="text" name="PostCode" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Telephone:</td>
<td><input type="text" name="Telephone" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">FaxNo:</td>
<td><input type="text" name="FaxNo" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="Insert record"></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
Can anyone see anything obvious, or is there a version clash somewhere ?
Best Regards
Austin Harvey.