Hi all, I'm on with learning php with some code I,ve downloaded , the codes a simple quiz but will also let me edit and delete the questions, I,ve created the code top delete, but for some reason the code won,t delete the entry. I,m using xampp,mysl,php, on win xp and myphpadmin to create the databases.Input and output to the database is fine, I can see php is passing the correct id in the address bar but still won,t delete, thanks in advance for any help <?php include("contentdb.php"); if(!isset($cmd)) { $result = mysql_query("SELECT id, question FROM $table ORDER BY id",$db); echo "<table>"; while ($row = mysql_fetch_array($result)) { $id = $row["id"]; $question = $row["question"]; if ($alternate == "1") { $color = "#ffffff"; $alternate = "2"; } else { $color = "#efefef"; $alternate = "1"; } /*this is were I delete*///////// echo "<tr bgcolor=$color><td>$id:</td><td>$question</td><td><a href='deletequiz2.php?cmd=delete&id=$id'onClick=\"return confirm('Are you sure?')\">delete</a> ]</td></tr>"; } } echo "</table>"; ?> ////////////////////////////////// And this is the seperate file in php to delete the entry <?php include("contentdb.php"); if($_GET["cmd"]=="delete") { $sql = mysql_query("DELETE FROM $table WHERE id=$id",$db); //$result = mysql_query($sql); echo "Row deleted!"; } ?> Thanks again ps Deleting is no problen in adminmyphp
Try using $_GET to fetch value of id. include("contentdb.php"); $id = $_GET["id"]; if($_GET["cmd"]=="delete") { $sql = mysql_query("DELETE FROM $table WHERE id=$id",$db); //$result = mysql_query($sql); echo "Row deleted!"; } PHP:
Make sure you replace: $id = $_GET["id"]; with: $id = intval($_GET["id"]); Something like this: deletequiz2.php?cmd=delete&id=1 or 1 would empty your table.