Help please!!
Posted: Wed Apr 02, 2008 7:56 pm
an error appears when i click on the edit button:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\program files\wamp\www\exam\editenglishquestions.php on line 61
Edit Question
question
choice A
choice B
choice C
choice D
answer
and i don't know what's the problem in my code.Please help
Here is my code:
please help

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\program files\wamp\www\exam\editenglishquestions.php on line 61
Edit Question
question
choice A
choice B
choice C
choice D
answer
and i don't know what's the problem in my code.Please help
Here is my code:
Code: Select all
<?
session_start();
?>
<!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>Untitled Document</title>
</head>
<body>
<p align="center"><img src="images/logo.jpg" width="800" height="200" /><a name="top" id="top"></a></p>
<table width="850" border="0" align="center" class="underresult">
<?
$db = mysql_connect("localhost");
mysql_select_db("examination",$db);
if(!isset($cmd))
{
$query = "SELECT *
FROM englishQuestions";
$result = mysql_query($query);
while($r=mysql_fetch_array($result)) {
$question_number = $r["englishQuestionID"];
$question = $r["question"];
$choiceA = $r["choiceA"];
$choiceB = $r["choiceB"];
$choiceC = $r["choiceC"];
$choiceD = $r["choiceD"];
$answer = $r["answer"];
if($i % 2){
$bg = "#BED9EF";
}
else{
$bg = "#FFFFFF";
}
echo '<tr bgcolor = "'.$bg.'">
<td width = "50" align = "center" valign = "center" >'.$question_number.'<td>';
echo '<td width = "250" align = "center" valign = "center">'.$question.'</td>';
echo '<td width = "100" align = "center" valign = "center">'.$choiceA.'</td>';
echo '<td width = "100" align = "center" valign = "center">'.$choiceB.'</td>';
echo '<td width = "100"align = "center" valign = "center">'.$choiceC.'</td>';
echo '<td width = "100" align = "center" valign = "center">'.$choiceD.'</td>';
echo '<td width = "100" align = "center" valign = "center">'.$answer.'</td>';
echo '<td width = "50" align = "center" valign = "center"><a href = "editEnglishQuestions.php?cmd=edit&englishQuestionID=$question_number">edit</a>';
'</tr>';
}
}
?>
</table>
<?
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["englishQuestionID"];
$sql = "SELECT * FROM englishQuestions WHERE englishQuestionID=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
<form action="editEnglishQuestions.php" method="post">
<table width="400" border="0" align="center" class="tableform1">
<tr>
<td width="85"> </td>
<td width="305" rowspan="2"><strong>Edit Question</strong></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td width="305"><input name="englishQuestionID" type="hidden" size="5" value= "<? echo $myrow["englishQuestionID"] ?>"/></td>
</tr>
<tr>
<td><div align="right">question</div></td>
<td><input name="edit_question" type="text" size="40" value = "<? echo $myrow["question"] ?>"/></td>
</tr>
<tr>
<td><div align="right">choice A </div></td>
<td><input name="edit_choiceA" type="text" value="<? echo $myrow["choiceA"] ?>" /></td>
</tr>
<tr>
<td><div align="right">choice B </div></td>
<td><input name="edit_choiceB" type="text" value="<? echo $myrow["choiceB"] ?>" /></td>
</tr>
<tr>
<td><div align="right">choice C </div></td>
<td><input name="edit_choiceC" type="text" value="<? echo $myrow["choiceC"] ?>" /></td>
</tr>
<tr>
<td><div align="right">choice D </div></td>
<td><input name="edit_choiceD" type="text" value="<? echo $myrow["choiceD"] ?>" /></td>
</tr>
<tr>
<td><div align="right">answer</div></td>
<td><input name="edit_answer" type="text" value="<? echo $myrow["answer"] ?>" /></td>
</tr>
<tr>
<td><div align="right">
<input type="hidden" name="cmd" value="edit" />
</div></td>
<td><input type="submit" name="submit" value="submit" /></td>
</tr>
</table>
</form>
<? } ?>
<?
if ($_POST["$submit"])
{
$edit_question = $_POST["edit_question"];
$edit_choiceA = $_POST["edit_choiceA"];
$edit_choiceB = $_POST["edit_choiceB"];
$edit_choiceC = $_POST["edit_choiceC"];
$edit_choiceD = $_POST["edit_choiceD"];
$edit_answer = $_POST["edit_answer"];
$sql = "UPDATE englishQuestions SET question='$edit_question',choiceA='$edit_choiceA',choiceB='$edit_choiceB', choiceC='$edit_choiceC', choiceD='$edit_choiceD', answer='$edit_answer' WHERE englishQuestionID=$id";
$result = mysql_query($sql);
echo "Thank you! Information updated.";
}
}
?>
</body>
</html>