saloo Posted February 17, 2007 Share Posted February 17, 2007 Hi. i found this script online and i thought all i need to do is just change the database name, username and password but when i try to run the script i got lots of notices. i got 4 fields and a button by the name of (enter information). once the admin fills out the form and click on the button(enter information), the information is stored in the database which does not. i dont know whats going on any help will be really appreciated. and here is the guy url who created the script and the test page. http://www.widgetmonkey.com/quiz/editquiz.php and here is my script <HTML> <link rel="stylesheet" href="quiz.css" type="text/css"> <body><center> <P> </P> <B>Admin area - edit the quiz</B> <?php include("contentdb.php"); $submit = isset($_POST['submit']); $id = ""; $update = ""; if($submit) { $sql = "INSERT INTO $table (question, opt1, opt2, opt3, answer) VALUES ('$question','$opt1','$opt2','$opt3','$answer')"; $result = mysql_query($sql); echo "<br><br>Question added to quiz.<br><br>"; include "qinsert.php"; } else if($update) { $sql = "UPDATE $table SET question='$question',opt1='$opt1',opt2='$opt2',opt3='$opt3',answer='$answer' WHERE id=$id"; $result = mysql_query($sql); echo "<br><br>The quiz has been succesfully updated.<br><br>\n"; } else if($id) { $result = mysql_query("SELECT * FROM $table WHERE id=$id",$db); $myrow = mysql_fetch_array($result); ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>"> <input type="hidden" name="id" value="<?php echo $myrow["id"]?>"> <b>Question:</b><br> <input type="Text" name="question" value="<?php echo $myrow["question"]?>" size="50"> <br> <b>Option 1:</b><br> <input type="Text" name="opt1" value="<?php echo $myrow["opt1"]?>" size="30"> <br> <b>Option 2:</b><br> <input type="Text" name="opt2" value="<?php echo $myrow["opt2"]?>" size="30"> <br> <b>Option 3:</b><br> <input type="Text" name="opt3" value="<?php echo $myrow["opt3"]?>" size="30"> <br> <b>Answer</b> (must be identical to correct option):<br> <input type="Text" name="answer" value="<?php echo $myrow["answer"]?>" size="30"> <br> <br> <input type="Submit" name="update" value="Update information"></form> <? } else { ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>"> <p><br> <b>Question:</b><br> <input type="Text" name="question" size="50"> <br> <b>Option 1:</b><br> <input type="Text" name="opt1" size="30"> <br> <b>Option 2:</b><br> <input type="Text" name="opt2" size="30"> <br> <b>Option 3:</b><br> <input type="Text" name="opt3" size="30"> <br> <b>Answer</b> (must be identical to correct option):<br> <input type="Text" name="answer" size="30"> <br> <br> <input type="Submit" name="submit" value="Enter information"> </p> </form> <? } ?> <a href="editquizlist.php">Back to list of quiz questions</a> </center> </body> </HTML> Link to comment https://forums.phpfreaks.com/topic/38912-php-script-not-updating-the-database/ Share on other sites More sharing options...
emehrkay Posted February 17, 2007 Share Posted February 17, 2007 try this $result = mysql_query($sql) or die (mysql_error()); Link to comment https://forums.phpfreaks.com/topic/38912-php-script-not-updating-the-database/#findComment-187142 Share on other sites More sharing options...
saloo Posted February 17, 2007 Author Share Posted February 17, 2007 hi thanks for the reply bro. let me show you my output when i click on the button this is what i get: Admin area - edit the quiz Notice: Undefined variable: question in c:\program files\easyphp1-7\www\quizv1.0\editquiz.php on line 14 Notice: Undefined variable: opt1 in c:\program files\easyphp1-7\www\quizv1.0\editquiz.php on line 14 Notice: Undefined variable: opt2 in c:\program files\easyphp1-7\www\quizv1.0\editquiz.php on line 14 Notice: Undefined variable: opt3 in c:\program files\easyphp1-7\www\quizv1.0\editquiz.php on line 14 Notice: Undefined variable: answer in c:\program files\easyphp1-7\www\quizv1.0\editquiz.php on line 14 Question added to quiz. Back to list of quiz questions it says that the question has been added to the quiz but when i click on (back to list of quiz questions) all i see is just one question which i entered manually through mysql and 3 blank fields. here is the output. Admin area - edit the quiz 1: who is the president of USA? [ edit ] [ delete ] 2: [ edit ] [ delete ] 3: [ edit ] [ delete ] 4: [ edit ] [ delete ] 5: [ edit ] [ delete ] here is my editquizlist.php script <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> and y am i getting so many notices ? i know it says undefined variable how can i get rid of those also. Thankyou . Link to comment https://forums.phpfreaks.com/topic/38912-php-script-not-updating-the-database/#findComment-187154 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.