please help me i can't figure out what's wrong with my code. it's not deleting in the database.
here is my code:
Code: Select all
<?
session_start();
$db = mysql_connect("localhost");
mysql_select_db("examination",$db);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Delete Logic Question</title>
<link href="Layout.css" rel="stylesheet" type="text/css" />
</head>
<body>
<p align="center"><img src="images/logo.jpg" width="800" height="200" /><a name="top" id="top"></a></p>
<table width="400" border="0" align="center" class="session">
<tr>
<td colspan="2" class="session" span>
<?
if(!$_SESSION['loggedin']){
echo '<div align = "center"><span class = "session"><br><font size = "3" color = "#000000"><strong>this page is for administrators only</font></strong></span></div><br><br>';
echo "unauthorized person keep out<br><br>";
echo '<font size = "1"><a href = "login.php">click here to log in </a></font><br><br>';
exit;
}
echo 'Delete Logic Question -- Good day '.$_SESSION['loggedin'].'.<br><br>';
$db = mysql_connect("localhost");
mysql_select_db("examination",$db);
?>
</td>
</tr>
</table>
<?
if($_GET["cmd2"]=="delete" || $_POST["cmd2"]=="delete")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["logicQuestionID"];
$sql = "SELECT * FROM logicQuestions WHERE logicQuestionID=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
<form action="deleteLogicQuestion.php" method="post">
<input type=hidden name="id" value="<?php echo $myrow["logicQuestionID"] ?>">
<table width="400" border="0" align="center" class="tableform1">
<tr>
<td width="85"> </td>
<td width="297" rowspan="2"><strong>Delete</strong></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><div align="right">Question #</div></td>
<td width="305"><input name="englishQuestionID" type="text" size="5" value= "<? echo $myrow["logicQuestionID"] ?>"/></td>
<td><input name="cmd2" type="hidden" id="delNum" value="delete"></td>
</tr>
<tr>
<td><div align="right"></div></td>
<td><input name="submit" type="submit" value="delete" /></td>
</tr>
</table>
</form><br />
<? } ?>
<?
if ($_POST["submit"])
{
$id = $_POST["logicQuestionID"];
$result = mysql_query("select * FROM logicQuestions
WHERE logicQuestionID = '$id'");
if(mysql_num_rows($result) > 0){
$result = mysql_query("delete from logicQuestions where logicQuestionID = '$id'");
echo "<br><div align = 'center'><font class = 'session'>Question Deleted.</font></div>";
}
else{
echo '<div align = "center"><font color = "red" face = "arial" size = "3"><i>Invalid Input<br>No Question Deleted</i></font></div>';
}
}
}
?>
<<br><span class = 'session'><div align = 'center'><a href = 'logicQuestions.php'><font size = '1'>Back to Logic Questions</font></a></div></span>
</body>
</html>
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: