View Full Version : SQL syntax error


MistressVivi
10-16-2004, 08:46 PM
Posting this here, because I'm not seeing a forum for it elsewhere ^^;
I'm trying to make a form that will allow people to fill things out on it and it will post to my website. I've been working on this for a few weeks, and managed to get a simplified version working. The problem is, now that I'm working on the actual one, I get an error that says 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 'update (date, title, author, update) VALUES ('Saturday, October
screenshot of the database (http://img.photobucket.com/albums/v321/melfra/database.jpg)
and here's the script, also
<?php
include("connect.php");
if(!empty($title)) {
$date = addslashes($date);
$title = addslashes($title);
$author = addslashes($author);
$update = addslashes($update);

$sql = "INSERT INTO update (id, date, title, author, update) VALUES ('NULL','$date','$title','$author','$update')";
$query = mysql_query($sql) or die("ERROR<br>" . mysql_error());
echo "Database Updated.";
} else {
?>
<form name="update" method="post" action="<?php echo $PHP_SELF; ?>">
<p>Updating, huh? Yar!</p>
<table width="100%" border="0" cellpadding="0" cellspacing="0">

<tr>
<td width="117"><font size="1">Date: </font> </td>
<td width="577">
<font size="1">
<input type="text" name="date" size="50">
</font>
</td>
</tr>
<tr>


<tr>
<td width="117"><font size="1">Title: </font> </td>
<td width="577">
<font size="1">
<input type="text" name="title" size="50">
</font>
</td>
</tr>
<tr>


<tr>
<td width="117"><font size="1">Author:</font></td>
<td width="577">
<font size="1">
<input type="text" name="author" size="50">
</font>
</td>
</tr>


<tr>
<td width="117"><font size="1">Update:</font></td>
<td width="577">
<font size="1">
<textarea name="update" size="50"></textarea>
</font>
</td>
</tr>


</table>
<p>

<input type="submit" name="submit" value="Submit"></font>
</p>
</form> <?php
}
?>
so, does anyone know what the heck I'm doing wrong with this?

bigolblob
10-16-2004, 10:41 PM
Change the line:
$sql = "INSERT INTO update (id, date, title, author, update) VALUES ('NULL','$date','$title','$author','$update')";

to:

$sql = "INSERT INTO `update` (`id`,`date`,`title`,`author`,`update`) VALUES ('NULL','$date','$title', '$author','$update')";

"Update" is used to update a row, so `'s are required so it won't think you're telling it to update a row. I added it to the other things too, just in case you would've gotten into other problems.

MistressVivi
10-18-2004, 02:01 AM
Yes, it worked! Thank you so much! xD

MistressVivi
10-18-2004, 05:37 PM
One more question, though. I try assigning styles to the rows and such in the following code, but I get parse errors when it's viewed. Otherwise, it works just fine (by the way, this is the view page for the previous table)
<style>
div {border: 1px solid #000000;
padding: 2px;
margin: 2px;}
</style>
<link rel="stylesheet" type="text/css" href="../graphics/cherry.css">
<?
include("connect.php");

$getupdates = mysql_query("SELECT * FROM `update` ORDER BY id DESC");
while($row = mysql_fetch_assoc($getupdates))
{
print("<div>$row[date]<br>$row[title]<br><br>$row[update]<br><br>$row[author]</div>");
}

?>
As soon as I change $row[date] to <font class="update">$row[date]</font> I get the parse error. Any idea with this one, or are styles with this kind of thing just impossible?

MistressVivi
10-18-2004, 08:06 PM
Aheh, sorry, scratch that last one. I figured it out - take out the quotes and it fixes itself. However, I try using punctuation in my entries (this is an automated update system =p), and it puts in backslashes before any apostraphies. Any way to fix this? I've seen it solved in javascript, but I've no clue how to make it read the apostraphies properly...