RyanSF07 Posted February 14, 2007 Share Posted February 14, 2007 I really can't figure this out. Please help. Any and all ideas appreciated. In testing this, the fields populate with data. I click "update information." I get the success message. BUT the update is never SET. That is, though I'm trying to update a field, the new data does not replace the old data in the database, eventhough I'm getting the success message. I'm pulling my hair out. What in the heck could I be missing? Thank you again for your time and help. PS This code looks gamey because I've tried so many different things. Even so, it works, and produces the result above. I'm missing something elemental, I guess ??? <?php session_start(); header("Cache-control: private"); //IE 6 Fix include("contentdb.php"); include "qinsert.php"; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <link href="main_styles.css" rel="stylesheet" type="text/css"> </head> <body> <div id = "edit_quiz_nav"> <table><tr> <td>Edit quiz:</td> <td><a href = "editquiz_details.php">details</a></td> <td><a href = "editquiz_questions.php">questions</a> </td> <td><a href = "editquiz_transcript.php">transcript</a></td> <td><a href = "editquiz_notes.php">notes</a></td> </tr> </table> </div> <br> <?php $id = $_GET[id]; $update = $_POST['update']; $question = $myrow['question']; $opt1 = $_POST['opt1']; $opt2 = $_POST['opt2']; $opt3 = $_POST['opt3']; $answer = $_POST['answer']; if ($update) { // php validation if ($_POST[question] <> "") { $a = TRUE; } else { $b = FALSE; $content .= "<p>Please enter a transcript for your quiz.</p>\n"; } } if ($a) { $sql = "UPDATE quiz SET question = '$question', opt1='$opt1', opt2='$opt2', opt3='$opt3', answer='$answer' WHERE id='$id'"; $result = mysql_query($sql); echo " The quiz has been succesfully updated. \n"; } else if($id) { $result = mysql_query("SELECT * FROM quiz WHERE quiz.id='$id'",$db); $myrow = mysql_fetch_array($result); ?> Edit this question.<?echo "$_GET[id] $id $_SESSION[get]";?> <form method="post" action="editquiz_updateQ.php"> <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> <? } ?> </body> </HTML> Quote Link to comment https://forums.phpfreaks.com/topic/38411-solved-update-trouble/ Share on other sites More sharing options...
benjaminbeazy Posted February 14, 2007 Share Posted February 14, 2007 you're not actually updating and you're success string isnt based on anything change it to this $result = mysql_query($sql); if($result){ echo "The quiz has been succesfully updated."; }else{ echo "Failed updating; } Quote Link to comment https://forums.phpfreaks.com/topic/38411-solved-update-trouble/#findComment-184231 Share on other sites More sharing options...
fenway Posted February 14, 2007 Share Posted February 14, 2007 At which point you should be echo-ing mysql_error() as well Quote Link to comment https://forums.phpfreaks.com/topic/38411-solved-update-trouble/#findComment-184295 Share on other sites More sharing options...
benjaminbeazy Posted February 14, 2007 Share Posted February 14, 2007 yeah that too... Quote Link to comment https://forums.phpfreaks.com/topic/38411-solved-update-trouble/#findComment-184299 Share on other sites More sharing options...
RyanSF07 Posted February 14, 2007 Author Share Posted February 14, 2007 The cut and paste didn't work.... If the trouble may be with one of the include files, what should I be looking for? As is, all seems to be in order. Thank you again-- very much -- for your help. Let's please solve this Ryan Quote Link to comment https://forums.phpfreaks.com/topic/38411-solved-update-trouble/#findComment-184386 Share on other sites More sharing options...
btherl Posted February 14, 2007 Share Posted February 14, 2007 There's a missing quote. try $result = mysql_query($sql); if($result){ echo "The quiz has been succesfully updated."; }else{ echo "Failed updating: " . mysql_error() . "\n$sql\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/38411-solved-update-trouble/#findComment-184414 Share on other sites More sharing options...
benjaminbeazy Posted February 14, 2007 Share Posted February 14, 2007 my bizzle.. Quote Link to comment https://forums.phpfreaks.com/topic/38411-solved-update-trouble/#findComment-184430 Share on other sites More sharing options...
RyanSF07 Posted February 14, 2007 Author Share Posted February 14, 2007 Hi Guys, Thank you very much for your help. I'm glad to get an error, though still making some simple mistake. Almost there! Please have a look Here is the error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/5640/domains/eslvideo.net/html/ESL_WebTech_2/editquiz_updateQ.php on line 62 (line 62 begins with: if($id) { ) Here is the code: <?php session_start(); header("Cache-control: private"); //IE 6 Fix include("contentdb.php"); include "qinsert.php"; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <link href="main_styles.css" rel="stylesheet" type="text/css"> </head> <body> <div id = "edit_quiz_nav"> <table><tr> <td>Edit quiz:</td> <td><a href = "editquiz_details.php">details</a></td> <td><a href = "editquiz_questions.php">questions</a> </td> <td><a href = "editquiz_transcript.php">transcript</a></td> <td><a href = "editquiz_notes.php">notes</a></td> </tr> </table> </div> <br> <?php $id = $_GET[id]; $update = $_POST['update']; $question = $myrow['question']; $opt1 = $_POST['opt1']; $opt2 = $_POST['opt2']; $opt3 = $_POST['opt3']; $answer = $_POST['answer']; if ($update) { // php validation if ($_POST[question] <> "") { $a = TRUE; } else { $b = FALSE; $content .= "<p>Please enter a transcript for your quiz.</p>\n"; } } if ($a) { $result = mysql_query($sql); if($result){ echo "The quiz has been succesfully updated."; } else{ echo "Failed updating: " . mysql_error() . "\n$sql\n"; } } if($id) { $sql = mysql_query("SELECT * FROM quiz WHERE quiz.id='$id'",$db); $myrow = mysql_fetch_array($result); } ?> Edit this question.<?echo "$_GET[id] $id $_SESSION[get]";?> <form method="post" action="editquiz_updateQ.php"> <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> <? ?> </body> </HTML> Quote Link to comment https://forums.phpfreaks.com/topic/38411-solved-update-trouble/#findComment-184701 Share on other sites More sharing options...
fenway Posted February 14, 2007 Share Posted February 14, 2007 You never define $sql.... Quote Link to comment https://forums.phpfreaks.com/topic/38411-solved-update-trouble/#findComment-184737 Share on other sites More sharing options...
RyanSF07 Posted February 14, 2007 Author Share Posted February 14, 2007 Hi again, The code below is producing the following error: Failed updating: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' Resource id #3' at line 1 UPDATE quiz SET question = '', opt1='call him', opt2='send this video to friends', opt3='both of the above', answer='both of the above' WHERE quiz.id='', Resource id #3 I'm googling this now. If you know the correct format to use for newer versions of MySQL, please let me know. (I'm new to this:) Might just be something simple like "quotes" instead of 'single quotes' ? Here's the code. Thanks again so much for your help! if ($update) { $sql = ("UPDATE quiz SET question = '$question', opt1='$opt1', opt2='$opt2', opt3='$opt3', answer='$answer' WHERE quiz.id='$id', $db"); $result = mysql_query($sql); if($result){ echo "The quiz has been succesfully updated."; } else{ echo "Failed updating: " . mysql_error() . "\n$sql\n"; } } else if($id) { $result = mysql_query("SELECT * FROM $table WHERE id=$id",$db); $myrow = mysql_fetch_array($result); Quote Link to comment https://forums.phpfreaks.com/topic/38411-solved-update-trouble/#findComment-184905 Share on other sites More sharing options...
RyanSF07 Posted February 14, 2007 Author Share Posted February 14, 2007 Hey Again, Now I'm getting this error again? Parse error: syntax error, unexpected T_ELSE in ...editquiz_updateQ.php on line 47 line 47 begins with: else if($id) Note the new format for listing values. Hope this works. Please help me eliminate the T-ESLE error. Thanks very much!! $sql = ("UPDATE quiz SET question = 'value[$question'], opt1='value[$opt1', opt2='value[$opt2]', opt3='value[$opt3]', answer='value[$answer]' WHERE quiz.id='$id', $db"); $result = mysql_query($sql); if($result){ echo "The quiz has been succesfully updated."; } else{ echo "Failed updating: " . mysql_error() . "\n$sql\n"; } else if($id) { $result = mysql_query("SELECT * FROM $table WHERE id=$id",$db); $myrow = mysql_fetch_array($result); } Quote Link to comment https://forums.phpfreaks.com/topic/38411-solved-update-trouble/#findComment-184928 Share on other sites More sharing options...
tauchai83 Posted February 14, 2007 Share Posted February 14, 2007 Here is your obvious mistake. else if($id) // u do not even have a matched if statement for this. So it is unexpected T_ELSE error{ $result = mysql_query("SELECT * FROM $table WHERE id=$id",$db); $myrow = mysql_fetch_array($result); // This should be change to mysql_fetch_assoc or mysql_fetch_row.You have put an inccorect parameter for mysql_fetch_array. It should contain MYSQL_NUM or MYSQL_ASSOC for the second parameter. eg, mysql_fetch_array($result, MYSQL_ASSOC)} Quote Link to comment https://forums.phpfreaks.com/topic/38411-solved-update-trouble/#findComment-184960 Share on other sites More sharing options...
tauchai83 Posted February 14, 2007 Share Posted February 14, 2007 For your case, if you would like to do PHP validation, add this: if($question == ''){ echo "<script>alert(\" Please fill in your question.\");history.go(-1)</script>"; }else{ if ($update) $query = "SELECT * FROM $table WHERE id='$id' "; $result = mysql_query($query); if ($result) { $query = "UPDATE quiz SET question = '$question', opt1='$opt1', opt2='$opt2', opt3='$opt3', answer='$answer' "; $result = mysql_query($query); echo "Update is successful! Thank You"; } Quote Link to comment https://forums.phpfreaks.com/topic/38411-solved-update-trouble/#findComment-184984 Share on other sites More sharing options...
RyanSF07 Posted February 14, 2007 Author Share Posted February 14, 2007 Thank you for your help tauchai83, Your code sample has moved things forward. Now, however, the changes take place to not only one row, but to all. They are global. In other words, $id = $_GET[id]; and WHERE id='$id' are not having any effect. If I change the question_text or answer_text to one question, all of the questions and answers in the table are updated to become that exact question and/or answer. Still, at least an update is happening. Hurray. Why is WHERE id='$id' failing? (Note: echoing $id and GET_[id] display the correct values.) If you have bit more time, I'd love to learn how to fix this. Thank you very much! <?php session_start(); header("Cache-control: private"); //IE 6 Fix include("contentdb.php"); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <link href="main_styles.css" rel="stylesheet" type="text/css"> </head> <body> <div id = "edit_quiz_nav"> <table><tr> <td>Edit quiz:</td> <td><a href = "editquiz_details.php">details</a></td> <td><a href = "editquiz_questions.php">questions</a> </td> <td><a href = "editquiz_transcript.php">transcript</a></td> <td><a href = "editquiz_notes.php">notes</a></td> </tr> </table> </div> <br> <?php $id = $_GET[id]; $update = $_POST['update']; $question = $_POST['question']; $opt1 = $_POST['opt1']; $opt2 = $_POST['opt2']; $opt3 = $_POST['opt3']; $answer = $_POST['answer']; if ($update) $query = "SELECT * FROM $table WHERE id='$id' "; $result = mysql_query($query); if ($result) { $query = "UPDATE quiz SET question = '$question', opt1='$opt1', opt2='$opt2', opt3='$opt3', answer='$answer' "; $result = mysql_query($query); echo "Update is successful! Thank You"; } if($id) { $result = mysql_query("SELECT * FROM $table WHERE id=$id"); $myrow = mysql_fetch_array($result); ?> Edit this question.<?echo "$_GET[id] $id $_SESSION[get]";?> <form method="post" action="editquiz_updateQ.php"> <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> <? } ?> </body> </HTML> Quote Link to comment https://forums.phpfreaks.com/topic/38411-solved-update-trouble/#findComment-185013 Share on other sites More sharing options...
fenway Posted February 15, 2007 Share Posted February 15, 2007 I'm confused -- i see no WHERE clause in your update statement... not do i see why the outer select is necessary at all. Quote Link to comment https://forums.phpfreaks.com/topic/38411-solved-update-trouble/#findComment-185567 Share on other sites More sharing options...
RyanSF07 Posted February 15, 2007 Author Share Posted February 15, 2007 Hey Fenway, Sorry. This problem has been solved. Where is the icon/button to click "solved"? A note on the PHP Help forum says it's at the bottom of the thread, but I don't see it. Is there another thread view? sorry for such a lame question, but I'd like to know how to signify solved to same yours and others' time. Thanks again very much for your help over the past couple days! Ryan Quote Link to comment https://forums.phpfreaks.com/topic/38411-solved-update-trouble/#findComment-185619 Share on other sites More sharing options...
fenway Posted February 15, 2007 Share Posted February 15, 2007 The button should be there... I'll check with the admins. Quote Link to comment https://forums.phpfreaks.com/topic/38411-solved-update-trouble/#findComment-185810 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.