PDA

View Full Version : Update script fails with syntax error


RysChwith
08-25-2005, 05:50 PM
I'm working on a script that will allow me to view records from a database and update them. For three of the tables in the database, it works fine. For the fourth one, however, it fails with a syntax error, and I'm not sure why.

The output I'm getting is this:Failed to update record because of: 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 'group="009", scope="k", startdate="2005-01-08", enddate="2005-0

Query string: UPDATE Events SET name="Kingdom 13th Night", group="009", scope="k", startdate="2005-01-08", enddate="2005-01-08", url="http://www.sylvanglen.org/local/12thnight.html", showonmain="y" WHERE eventid="0015"The code I'm using is this://updates record in database and displays table
function updateRecord( $tableName, $tableKey, $queryValue ) {
$query = "UPDATE " . $tableName . " SET ";
foreach( $_POST as $field => $contents ) {
if( $field != "submit" && $field != $tableKey ) {
$query .= $field . "=\"" . $contents . "\", ";
}
}
$query = substr( $query, 0, $query.length - 2 );
$query .= " WHERE " . $tableKey . "=\"" . $queryValue . "\"";

//if query is successful, show success message
if( mysql_query( $query ) ) {
print " <div class = \"content\">\n <p>Record updated successfully.</p>\n";
print " </div>\n";
} else { //if query fails, display failure message
print " <div class = \"content\">\n <p>Failed to update record because of: ";
print mysql_error() . "</p>\n";
print " <p>Query string: " . $query . "</p>\n";
print " </div>\n";
}

viewTable( $tableName );
} //end updateRecordThe structure of the database table in question is:

eventid (auto-number, key)
name (string)
group (integer, limit 3)
scope (character)
startdate (date)
enddate (date)
url (string)
showonmain (character [I think it's an enum])

The script doesn't send the key, because that's not supposed to change. This isn't a problem on the other tables, so I'm figuring it can't be the problem here. I've tried removing the quotes around the group entry, but that hasn't changed anything.

Anyone have any thoughts?

Rys

RysChwith
08-25-2005, 07:05 PM
<swear src = "RysChwith" lang = "foul" target = "_self" />

Hey, Scoutt, remember all those times I asked about MySQL syntax errors and it turned out to be because I used "group" as the name for a table or column?

*grumble*

Rys