lhbdan Posted May 11, 2011 Share Posted May 11, 2011 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>"; } Quote Link to comment https://forums.phpfreaks.com/topic/236060-code-errors/ Share on other sites More sharing options...
fugix Posted May 11, 2011 Share Posted May 11, 2011 firstly, can you show me the line that the error is referring to please Quote Link to comment https://forums.phpfreaks.com/topic/236060-code-errors/#findComment-1213554 Share on other sites More sharing options...
PFMaBiSmAd Posted May 11, 2011 Share Posted May 11, 2011 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.) Quote Link to comment https://forums.phpfreaks.com/topic/236060-code-errors/#findComment-1213556 Share on other sites More sharing options...
fugix Posted May 11, 2011 Share Posted May 11, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/236060-code-errors/#findComment-1213557 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.