Re: deleting a record.

From: Date: Tue, 26 Nov 2002 23:05:09 +0000
Subject: Re: deleting a record.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-126199@lists.php.net to get a copy of this message
<? // get the list of resellers from the db $res = mysql_query("SELECT * FROM resellers ORDER BY id"); // print all records in the DB while ($myrow = mysql_fetch_array($res)){ echo "<tr><td><div align='center'><font class=\"content\">".$myrow['id']."</font></div> </td><td>&nbsp;</td><td><div align='justify'><font class=\"content\">".$myrow['company']."</font></div></td>"; printf("<td><font class='content'><a href=\"%s?op=resellers&id=%s&delete=yes\">(DELETE)</a></font></td></tr>", $PHP_SELF, $myrow["id"]); }?>
There's an easier way to display this. It should make your life easier...made mine. Take a look: <? // get the list of resellers from the db $res = mysql_query("SELECT * FROM resellers ORDER BY id"); // print all records in the DB while ($myrow = mysql_fetch_array($res)): ?> <tr><td><div align='center'> <font class="content"><?=$myrow['id']?></font> </div></td><td>&nbsp;</td><td> <div align='justify'><font class="content"> <?=$myrow['company']?></font></div></td><td><font class="content"> <a href="<?=$PHP_SELF?>?op=resellers&id=<?=$myrow['id']?>&delete=yes"> (DELETE)</a></font></td></tr> <? endwhile; ?>
now when I click on delete it just reloads the page and doesn't delete the record. I have this code before anything else on the page to handle the delete... if($delete){ $res= mysql_query("DELETE FROM resellers WHERE id=$id"); header("Location: admin2.php?op=resellers"); }
What you should do here is check to see if $res is failing, simply by doing the following: if(!$res) echo "error"; Then, place an 'exit;' after the header(...) command to see if the $delete variable is actually being passed. -- Kyle Gibson admin(at)frozenonline.com http://www.frozenonline.com/

« previous php.general (#126199) next »