wrathican Posted June 19, 2007 Share Posted June 19, 2007 hi ive never used mysql UPDATE before in a php script. ive made a kind of CMS system so a user can update the content of a page. ive tried to make the process script and it uses an if statement to see if the variables contains a value, if it does it runs the update query if not it says there was an error. but when ive put some input into the field and run the script it outputs what i made if th script has run properly. but when i go to the page that i updated the content its still the same. any help? here is the code for my process form: <?php $id = $_POST['id']; $title = $_POST['title']; $content = $_POST['content']; if ($id == "") { echo "I\'m sorry but there seems to be an error. Please go back and try again."; }else{ $query = "UPDATE cy_content SET cont_title='$title', cont_content='$content' WHERE id='$id'"; mysql_query($query); echo 'Page has been updated. Please go <a href="cms.php">back</a> and select another back to update.'; }; ?> Quote Link to comment https://forums.phpfreaks.com/topic/56274-update-not-working/ Share on other sites More sharing options...
GingerRobot Posted June 19, 2007 Share Posted June 19, 2007 Whenever you're looking to debug something with a query, you should do something like the following: mysql_query($query) or die(mysql_error().'<br />Query:'.$query); If there is still no error found, then it's always worth echoing the contents of the query to see what values are in the variables: mysql_query($query) or die(mysql_error().'<br />Query:'.$query); echo '<br />Query:'.$queryl Quote Link to comment https://forums.phpfreaks.com/topic/56274-update-not-working/#findComment-278005 Share on other sites More sharing options...
gterre Posted June 19, 2007 Share Posted June 19, 2007 You should establish a connection to the database before performing any queries. Quote Link to comment https://forums.phpfreaks.com/topic/56274-update-not-working/#findComment-278052 Share on other sites More sharing options...
teng84 Posted June 19, 2007 Share Posted June 19, 2007 even if you put the connection i dont think the update function will work try this $query = "UPDATE cy_content SET cont_title='".$title."', cont_content='".$content."' WHERE id= $id "; this "....... WHERE id= $id "//ok "....... WHERE id= ".$id." "//ok "....... WHERE id= '".$id."' "//ok Quote Link to comment https://forums.phpfreaks.com/topic/56274-update-not-working/#findComment-278056 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.