Jump to content

missing something


tabatsoy

Recommended Posts

please help me with my code i can't figure out what the problem is. it's not deleting anything in my database.

    Here is my code:

                   

<?
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>

Link to comment
https://forums.phpfreaks.com/topic/101715-missing-something/
Share on other sites

I'm guessing you're talking about this chunk of code:

<?php
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>';
	}
}

Link to comment
https://forums.phpfreaks.com/topic/101715-missing-something/#findComment-520405
Share on other sites

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.