Jump to content

Deleting A Row


AnAmericanGunner

Recommended Posts

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

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

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

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.