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

Link to comment
Share on other sites

$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.

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.