AnAmericanGunner Posted April 15, 2010 Share Posted April 15, 2010 I found that the query is DELETE FROM table WHERE restrictions. So far I got this: <? session_name('usersession'); session_start(); $title = "My Account"; $home = "not"; $guests = "not"; $forum = "not"; $est = "not"; $res = "not"; $my = "my"; $contact = "not"; include('includes/database.php'); include('includes/header.php'); if(!isset($peacock)) { include ('includes/loginform.php'); include('includes/footer.php'); exit(); } ?> <? if (isset($_POST['id'])) { $sql = "DELETE FROM establishments WHERE id = '$id'; if (mysql_query($sql)) { echo 'Ta-Da!'; } else { echo '<p>Error: ' . mysql_error() . '</p>'; } include('includes/footer.php'); ?> I get an unexpected $end. What I'd like it to do is when a user hits 'delete' on the main page to remove the establishment, it deletes i and then displays a "Establishment "(establishment name)" Successfully Removed" note, with the URL to return to the myaccount.php page. Link to comment https://forums.phpfreaks.com/topic/198582-deleting-a-row/ Share on other sites More sharing options...
Ken2k7 Posted April 15, 2010 Share Posted April 15, 2010 You missed a closing brace } for your if statement. Also, in your $sql query, you're missing a closing ". May I suggest using Notepad++ or some text editor that highlights syntax to prevent these fundamental errors? Link to comment https://forums.phpfreaks.com/topic/198582-deleting-a-row/#findComment-1042065 Share on other sites More sharing options...
AnAmericanGunner Posted April 15, 2010 Author Share Posted April 15, 2010 I currently use regular old Notepad. I will look into Notepad++, however. Here is the new coding: <? session_name('usersession'); session_start(); $title = "My Account"; $home = "not"; $guests = "not"; $forum = "not"; $est = "not"; $res = "not"; $my = "my"; $contact = "not"; include('includes/database.php'); include('includes/header.php'); if(!isset($peacock)) { include ('includes/loginform.php'); include('includes/footer.php'); exit(); } ?> <? if (isset($_POST['id'])) { $sql = "DELETE FROM establishments WHERE id = '$id'"; } if (mysql_query($sql)) { echo 'Ta-Da!'; } else { echo '<p>Error: ' . mysql_error() . '</p>'; } include('includes/footer.php'); ?> and I get another error saying the Query was empty. Link to comment https://forums.phpfreaks.com/topic/198582-deleting-a-row/#findComment-1042071 Share on other sites More sharing options...
Ken2k7 Posted April 15, 2010 Share Posted April 15, 2010 You placed the } in the wrong place. You should've placed it before the last include line. It helps to put some comments in your code so you know what each block of code should do. Otherwise, you often get blinded by the code and start randomly putting things where they don't belong. Link to comment https://forums.phpfreaks.com/topic/198582-deleting-a-row/#findComment-1042074 Share on other sites More sharing options...
AnAmericanGunner Posted April 15, 2010 Author Share Posted April 15, 2010 Alright, I got it figured out xD I moved the } and added a form at the top to list the ID and that seemed to do the trick. Link to comment https://forums.phpfreaks.com/topic/198582-deleting-a-row/#findComment-1042079 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.