Jump to content

PHP - SQL Delete row query


ipPHPadmin

Recommended Posts

Hello everyone,

 

I am attempting to delete a row from my SQL database.  I'm using phpMyAdmin for my database manager.  I've tried to do this two different ways (which are posted below), but each way is initiated by selecting a delete button on the previous page.  I'm not getting any errors, and it is running through and displaying the "Success!" line, but not deleting anything.

 

Thanks in advance for any help.

 

 

Attempt #1:

 

$max = mysql_query("SELECT MAX(ART_ID) AS maxAID FROM Artisan");

 

$numrows = mysql_num_rows($max);

 

if($numrows == 0)

{

echo "Artisan was not deleted.";

?>

                ---some html filler that doesn't use the php above or below----

      <?php

}

else

{

while (mysql_fetch_array($max))

{

$ART_ID = $row['maxAID'];

$deleteArtisan = mysql_query ("DELETE FROM Artisan WHERE ART_ID = '$ART_ID'");

$deleteAnswers = mysql_query ("DELETE FROM ArtisanAnswer WHERE ART_ID = '$ART_ID'");

 

echo "success!";

 

if (!$deleteArtisan || !$deleteAnswers)

{

die ("error: " .mysql_error());

}

}

}

 

 

Attempt #2:

 

$id = $_REQUEST['ART_ID'];

 

$max = mysql_query("SELECT * FROM Artisan WHERE ART_ID = '$id'");

 

while(mysql_fetch_row($max))

{

$deleteArtisan = mysql_query ("DELETE FROM Artisan WHERE ART_ID = '$ART_ID'");

$deleteAnswers = mysql_query ("DELETE FROM ArtisanAnswer WHERE ART_ID = '$ART_ID'");

 

echo "success!";

 

if (!$deleteArtisan || !$deleteAnswers)

{

die ("error: " .mysql_error());

}

}

Link to comment
Share on other sites

something like this...

 

<?php

$max = mysql_query("SELECT MAX(ART_ID) AS maxAID FROM Artisan");

if(!mysql_num_rows($max))
   {
      echo "Artisan was not deleted.";

   }
   else
       {

         while($row=mysql_fetch_array($max)) 
   {

         $ART_ID = $row['maxAID'];
           mysql_query ("DELETE FROM Artisan WHERE ART_ID = '$ART_ID'") or die(mysql_error());
           mysql_query ("DELETE FROM ArtisanAnswer WHERE ART_ID = '$ART_ID'") or die(mysql_error());
         
         echo "Row(s) successfully deleted!";
   }
    }	   
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.