|
Posted by Sean on 12/14/06 14:39
You are missing the ID from the blog_id =
Like
DELETE FROM blog_entries WHERE blog_id = 7
I don't think that you would LIMIT a deletion.
"cerberus" <ian.themacman@gmail.com> wrote in message
news:1166073799.824804.177920@80g2000cwy.googlegroups.com...
> 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]
|