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
https://forums.phpfreaks.com/topic/219927-php-sql-delete-row-query/
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!";
   }
    }	   
?>

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.