chadvirus
6-18-04, 11:54 AM
I'm using DreamweaverMX's Record Update form and it was working fine on every other page I've used it on, but for some reason I'm getting an 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 'long='
Thoughts/Suggestions? Thanks in advance.
<?php require_once('Connections/local.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 = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}
if ((isset($HTTP_POST_VARS["MM_update"])) && ($HTTP_POST_VARS["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE news SET title=%s, long=%s, short=%s, active=%s WHERE news_id=%s",
GetSQLValueString($HTTP_POST_VARS['title'], "text"),
GetSQLValueString($HTTP_POST_VARS['long'], "text"),
GetSQLValueString($HTTP_POST_VARS['short'], "text"),
GetSQLValueString($HTTP_POST_VARS['active'], "int"),
GetSQLValueString($HTTP_POST_VARS['news_id'], "int"));
mysql_select_db($database_local, $local);
$Result1 = mysql_query($updateSQL, $local) or die(mysql_error());
$updateGoTo = "admin-news.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
$colname_AdminEditRecordset = "1";
if (isset($HTTP_GET_VARS['newsID'])) {
$colname_AdminEditRecordset = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['newsID'] : addslashes($HTTP_GET_VARS['newsID']);
}
mysql_select_db($database_local, $local);
$query_AdminEditRecordset = sprintf("SELECT * FROM news WHERE news.news_id = %s", $colname_AdminEditRecordset);
$AdminEditRecordset = mysql_query($query_AdminEditRecordset, $local) or die(mysql_error());
$row_AdminEditRecordset = mysql_fetch_assoc($AdminEditRecordset);
$totalRows_AdminEditRecordset = mysql_num_rows($AdminEditRecordset);
?>
<?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Edit News Item</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">News_id:</td>
<td><?php echo $row_AdminEditRecordset['news_id']; ?></td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">Title:</td>
<td>
<textarea name="title" cols="50" rows="5"><?php echo $row_AdminEditRecordset['title']; ?></textarea>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">Long:</td>
<td>
<textarea name="long" cols="50" rows="5"><?php echo $row_AdminEditRecordset['long']; ?></textarea>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">Short:</td>
<td>
<textarea name="short" cols="50" rows="5"><?php echo $row_AdminEditRecordset['short']; ?></textarea>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="Update Record">
</td>
</tr>
</table>
<input type="hidden" name="active" value="<?php echo $row_AdminEditRecordset['active']; ?>">
<input type="hidden" name="MM_update" value="form1">
<input type="hidden" name="news_id" value="<?php echo $row_AdminEditRecordset['news_id']; ?>">
</form>
<p> </p>
</body>
</html>
<?php
mysql_free_result($AdminEditRecordset);
?>
:confused:
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 'long='
Thoughts/Suggestions? Thanks in advance.
<?php require_once('Connections/local.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 = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}
if ((isset($HTTP_POST_VARS["MM_update"])) && ($HTTP_POST_VARS["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE news SET title=%s, long=%s, short=%s, active=%s WHERE news_id=%s",
GetSQLValueString($HTTP_POST_VARS['title'], "text"),
GetSQLValueString($HTTP_POST_VARS['long'], "text"),
GetSQLValueString($HTTP_POST_VARS['short'], "text"),
GetSQLValueString($HTTP_POST_VARS['active'], "int"),
GetSQLValueString($HTTP_POST_VARS['news_id'], "int"));
mysql_select_db($database_local, $local);
$Result1 = mysql_query($updateSQL, $local) or die(mysql_error());
$updateGoTo = "admin-news.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
$colname_AdminEditRecordset = "1";
if (isset($HTTP_GET_VARS['newsID'])) {
$colname_AdminEditRecordset = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['newsID'] : addslashes($HTTP_GET_VARS['newsID']);
}
mysql_select_db($database_local, $local);
$query_AdminEditRecordset = sprintf("SELECT * FROM news WHERE news.news_id = %s", $colname_AdminEditRecordset);
$AdminEditRecordset = mysql_query($query_AdminEditRecordset, $local) or die(mysql_error());
$row_AdminEditRecordset = mysql_fetch_assoc($AdminEditRecordset);
$totalRows_AdminEditRecordset = mysql_num_rows($AdminEditRecordset);
?>
<?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Edit News Item</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">News_id:</td>
<td><?php echo $row_AdminEditRecordset['news_id']; ?></td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">Title:</td>
<td>
<textarea name="title" cols="50" rows="5"><?php echo $row_AdminEditRecordset['title']; ?></textarea>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">Long:</td>
<td>
<textarea name="long" cols="50" rows="5"><?php echo $row_AdminEditRecordset['long']; ?></textarea>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">Short:</td>
<td>
<textarea name="short" cols="50" rows="5"><?php echo $row_AdminEditRecordset['short']; ?></textarea>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="Update Record">
</td>
</tr>
</table>
<input type="hidden" name="active" value="<?php echo $row_AdminEditRecordset['active']; ?>">
<input type="hidden" name="MM_update" value="form1">
<input type="hidden" name="news_id" value="<?php echo $row_AdminEditRecordset['news_id']; ?>">
</form>
<p> </p>
</body>
</html>
<?php
mysql_free_result($AdminEditRecordset);
?>
:confused: