Jump to content

My script is not deleting the question from the database


saloo

Recommended Posts

hi. i have a form which is connected to my database and is accessible by the admin. admin can delete questions and add questions. my add question works but for some reason my delete does not work. here is my script

editquizlist.php

<HTML>
<link rel="stylesheet" href="quiz.css" type="text/css">
<body><center>
<P> </P>

<B>Admin area - edit the quiz</B>
<br><br>
  <table width="300" border="0" cellspacing="0" cellpadding="0">

        <?php

include("contentdb.php");

$result = mysql_query("SELECT id, question FROM $table ORDER BY id",$db);

echo "<table>";

while ($row = mysql_fetch_array($result))
{
$alternate = "";

$id = $row["id"];
$question = $row["question"];
if ($alternate == "1") {
$color = "#ffffff";
$alternate = "2";
}
else {
$color = "#efefef";
$alternate = "1";
}
echo "<tr bgcolor=$color><td>$id:</td><td>$question</td><td>[ <a href='editquiz.php?id=$id'>edit</a> ]</td><td>[ <a href='deletequiz.php?id=$id' onClick=\"return confirm('Are you sure?')\">delete</a> ]</td></tr>";
}
echo "</table>";
?>
        <br>
        <br>
        <a href="editquiz.php">Add a new question to the quiz</a></td>
    </tr>
  </table>
  <br>
  <br>
<a href="quizinfo.php">See the full quiz table</a>
</center>
</body>
</HTML>

here is my deletequiz.php

<HTML>
<link rel="stylesheet" href="quiz.css" type="text/css">
<center>
<?php
include("contentdb.php");

mysql_query("DELETE FROM $table WHERE id=$id",$db);
echo "<P> </P>";

echo "<B>Admin area - delete a quiz question<br><br></B>";

echo "Question deleted<br><br>";
echo "<a href='editquizlist.php'>Back to list of quiz questions</a>";
?>
</center>
</HTML>

it looks fine to me. any help will be really appreciated.

Thanks

$sql = "DELETE FROM $table WHERE id=$id";

mysql_query($sql,$db) OR die('SQL: '.$sql.' - Error: '.mysql_error());

 

You never define $id, it needs to be $id = $_GET['id']; before the query, since you can't count on register_globals being on.

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.