Jump to content

Code errors...


lhbdan

Recommended Posts

I wrote the code below as a way of deleting books from a database. The variables sent to this piece of code come from the page before it, through checkboxes with names corresponding to books, for example the page may have 3 checkboxes with the names 3, 4 and 5. If the user was to select checkbox 4, the variable 4 would be sent through post to this piece of code. The code below selects all of the books from the database in the users school, and then cycles through it, checking whether a book should be deleted by checking whether the post value for that book has been set, eg. if book three has been sent, isset($_POST[$temp]) should return a true, and thus the book is deleted from the database via the mysql_query. The code however will not run, currently I am getting

Parse error: syntax error, unexpected T_STRING in /home/textexch/public_html/home/exchange/deletebooks.php on line 81, but i fear there are other problems. Does anyone have any advice as to how to do this better?

 

$result = mysql_query("SELECT * FROM `books` WHERE School ='".$_COOKIE['School']."'");
while($row = mysql_fetch_array($result)){
$temp = $row['BookID'];
if(isset($_POST[$temp])){
	mysql_query("DELETE FROM books WHERE BookID = '$Delete');
}
}
if (mysql_affected_rows() == 0)
{
echo "sorry didn't work";
}
else {
echo "Books successfully deleted. Return home <a href='../'>here</a>";
}

Link to comment
https://forums.phpfreaks.com/topic/236060-code-errors/
Share on other sites

You are missing a double-quote on the end of your DELETE query statement.

 

You should be using a programming editor with color highlighting (that's how I pinpointed where the problem was - the colors stopped changing because everything after the missing quote was treated as part of that string.)

Link to comment
https://forums.phpfreaks.com/topic/236060-code-errors/#findComment-1213556
Share on other sites

You are missing a double-quote on the end of your DELETE query statement.

 

You should be using a programming editor with color highlighting (that's how I pinpointed where the problem was - the colors stopped changing because everything after the missing quote was treated as part of that string.)

good catch, missed it....ihbdan if you have further errors let us know

Link to comment
https://forums.phpfreaks.com/topic/236060-code-errors/#findComment-1213557
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.