You are here: I get a syntax error when trying to learn code in a quick start guide. « PHP SQL « IT news, forums, messages
I get a syntax error when trying to learn code in a quick start guide.

Posted by cerberus on 12/14/06 05:23

I'm totally new to PHP and MySQL. I'm using a quick start guide to make
a little blog. I get:

"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 'LIMIT 1' at line 1. The query was DELETE FROM blog_entries WHERE
blog_id= LIMIT 1."

The PHP version is 4.4.4 and MySQL is 4.1.21-standard.

It appears to become from the query definition for the "DELETE FROM"
call. I've put a small --> next to the code in question. The code is:


<?php //delete_entry.php
//This script deletes blog entries from the database.

//Address error handling.
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);

//Connect and select.
if ($dbc = mysql_connect ("localhost", "********", "*********")) {

if (!@mysql_select_db ('emanon_myblog')) {
die ('<p>Could not select the database because: <b>' . mysql_error()
.. '</b></p>');
}

} else {
die ('<p>Could not connect the database because: <b>' . mysql_error()
.. '</b></p>');
}

if (isset ($_POST['submit'])) {

//Define the query.
--> $query = "DELETE FROM blog_entries WHERE blog_id={$_POST['id']}
LIMIT 1";
$r = mysql_query ($query); //Execute the query.

//Report the result.
if (mysql_affected_rows() == 1) {
print '<p>The blog entry has been deleted.</p>';
} else {
print "<p>Could not delete the entry because: <b>" .mysql_error().
"</b>. The query was $query.</p>";
}

} else { //Display the entry in a form.

//Check for a valid entry ID in the URL.
if (is_numeric ($_GET['id'])) {

//Define the query.
$query = "SELECT * FROM blog_entries WHERE blog_id={$_GET['id']}";
if ($r = mysql_query ($query)) { //Run the query

$row = mysql_fetch_array ($r); // Regtrieve the information.

//Make the Form
print '<form action="delete_entry.php" method="post">
<p>Are you sure you want to delete this entry?</p>
<p><h3>' . $row['title'] . '</h3>' .
$row['entry'] . '<br />
<input type="hidden" name="id" value"' . $_GET['id'] . '" />
<input type="submit" name="submit" value="Delete this Entry!" /></p>
</form>';

} else { //Couldn't get the information.
print "<p>Could not retrieve the entry because: <b>" . mysql_error()
.. "</b>. The query was $query.</p>";
}
}
}// End of Main IF.

mysql_close(); // Close database connection.

?>

As I'm a total noob, any help would be much appreciated.

Thanks in advance

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация