tabatsoy Posted April 3, 2008 Share Posted April 3, 2008 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: <? 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> please help Link to comment https://forums.phpfreaks.com/topic/99294-solved-help-please/ Share on other sites More sharing options...
almightyegg Posted April 3, 2008 Share Posted April 3, 2008 what is line 61? Link to comment https://forums.phpfreaks.com/topic/99294-solved-help-please/#findComment-508042 Share on other sites More sharing options...
tabatsoy Posted April 3, 2008 Author Share Posted April 3, 2008 $myrow = mysql_fetch_array($result); that's line 61. please help ??? Link to comment https://forums.phpfreaks.com/topic/99294-solved-help-please/#findComment-508044 Share on other sites More sharing options...
almightyegg Posted April 3, 2008 Share Posted April 3, 2008 Change: $sql = "SELECT * FROM englishQuestions WHERE englishQuestionID=$id"; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); To This: $result = mysql_query("SELECT * FROM englishQuestions WHERE englishQuestionID = '$id'") or die(mysql_error()); $myrow = mysql_fetch_array($result); Now if you get an error it will tell you exactly what's wrong Link to comment https://forums.phpfreaks.com/topic/99294-solved-help-please/#findComment-508048 Share on other sites More sharing options...
tabatsoy Posted April 3, 2008 Author Share Posted April 3, 2008 no more errors but it didn't retrieve the row that i wanted to edit ??? Link to comment https://forums.phpfreaks.com/topic/99294-solved-help-please/#findComment-508057 Share on other sites More sharing options...
almightyegg Posted April 3, 2008 Share Posted April 3, 2008 What did it retrieve? Link to comment https://forums.phpfreaks.com/topic/99294-solved-help-please/#findComment-508063 Share on other sites More sharing options...
tabatsoy Posted April 3, 2008 Author Share Posted April 3, 2008 nothing. blank spaces ;D please help no more rides please! Link to comment https://forums.phpfreaks.com/topic/99294-solved-help-please/#findComment-508075 Share on other sites More sharing options...
darkfreaks Posted April 3, 2008 Share Posted April 3, 2008 <?php ini_set('error_reporting',E_ALL);?> Link to comment https://forums.phpfreaks.com/topic/99294-solved-help-please/#findComment-508076 Share on other sites More sharing options...
Drezard Posted April 3, 2008 Share Posted April 3, 2008 change: $result = mysql_query($query); to: $result = mysql_query($query) or die(mysql_error()); and see what the error says. Link to comment https://forums.phpfreaks.com/topic/99294-solved-help-please/#findComment-508079 Share on other sites More sharing options...
almightyegg Posted April 3, 2008 Share Posted April 3, 2008 Try changing things like this: value= "<? echo $myrow["englishQuestionID"] ?>" to: value= "<? echo "$myrow[englishQuestionID]"; ?>" Link to comment https://forums.phpfreaks.com/topic/99294-solved-help-please/#findComment-508092 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.