steve012345 Posted June 2, 2008 Share Posted June 2, 2008 I currently have a page interacting with a questions database for a questionnaire site. I can add questions fine but the edit questions part is giving me the error within the code and not updating the question table. here is the code, <? if(isset($_POST['Submit'])) { $question=$_POST['txtquestion']; if($_GET['editid']!="") { $sql="update question set question=$question where questionid=".$_GET['editid']; } else { $sql="insert into question(question) values ('$question')"; } $res=mysql_query($sql,$link); if($res) { echo "<script>alert('Successfully Added!');</script>"; echo "<meta http-equiv='refresh' content='0;url=managequestion.php'>"; exit(); } else { echo "Question not Added/Updated"; } } ?> please help! Quote Link to comment https://forums.phpfreaks.com/topic/108412-edit-field-problem/ Share on other sites More sharing options...
wildteen88 Posted June 2, 2008 Share Posted June 2, 2008 What error(s) are you getting? Is it the Question not Added/Updated message? If so there is more than likely a problem with your query change: $res=mysql_query($sql,$link); to: $res=mysql_query($sql,$link) or die('MySQL Query Error!<br />Query: <tt>' . $sql . '</tt><br >Error: ' . mysql_error()); If there is a problem within your sql query then an error will be displayed. Quote Link to comment https://forums.phpfreaks.com/topic/108412-edit-field-problem/#findComment-555781 Share on other sites More sharing options...
steve012345 Posted June 2, 2008 Author Share Posted June 2, 2008 Yes it is a problem with my sql query but what I don't understand is I can add a new question but can't update an exisiting one even though I am using the same fields. Quote Link to comment https://forums.phpfreaks.com/topic/108412-edit-field-problem/#findComment-555799 Share on other sites More sharing options...
wildteen88 Posted June 2, 2008 Share Posted June 2, 2008 Is an error displayed with my changes applied? Could you post the error here Quote Link to comment https://forums.phpfreaks.com/topic/108412-edit-field-problem/#findComment-555802 Share on other sites More sharing options...
steve012345 Posted June 2, 2008 Author Share Posted June 2, 2008 yes the error is MySQL Query Error! Query: update question set question=The aims of the unit were clearxcvcx where =1 Error: 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 'aims of the unit were clearxcvcx where =1' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/108412-edit-field-problem/#findComment-555806 Share on other sites More sharing options...
wildteen88 Posted June 2, 2008 Share Posted June 2, 2008 You need to wrap quotes around the value for the question field: $sql="UPDATE question SET question='$question' WHERE questionid=".$_GET['editid']; Quote Link to comment https://forums.phpfreaks.com/topic/108412-edit-field-problem/#findComment-555817 Share on other sites More sharing options...
steve012345 Posted June 2, 2008 Author Share Posted June 2, 2008 many thanks knew it would be simple Quote Link to comment https://forums.phpfreaks.com/topic/108412-edit-field-problem/#findComment-556084 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.