garethhall Posted July 6, 2008 Share Posted July 6, 2008 Hi guys can anyone see why my database doesnt want to update. I dont understand why it dont work? Thats is to say it is not updating the database. When i echo $sql it outputs all the right values as far as i can tell. I have confirmed that my username has got the right privileges. I always get else part of the if statement echoing? What confuses me even more is that this script work on my localhost where i developed it. But not on my Websever? Any help would be great. <?php require_once('../Connections/updateContent.php'); ?> <?php $newContent = $_POST[content]; $newContent = addslashes($newContent); $Updatepage = $_GET[pageName]; $sql = "UPDATE webContent SET pageContent = '$newContent' WHERE pageName = '$Updatepage'"; $test = mysql_query($sql); if($test == true){ echo "Database updated"; }else{ echo "Error updating Database"; }; mysql_select_db($database_updateContent, $updateContent); $query_index = "SELECT * FROM webContent WHERE pageName = '$_GET[pageName]'"; $index = mysql_query($query_index, $updateContent) or die(mysql_error()); $row_index = mysql_fetch_assoc($index); $totalRows_index = mysql_num_rows($index); echo $sql; ?> Quote Link to comment Share on other sites More sharing options...
ocpaul20 Posted July 6, 2008 Share Posted July 6, 2008 I always use sprintf to build my sql statement as it avoids some of the quotes, and I only test for FALSE if it has failed. The other thing I do is to print out the sqery string after I have built it and, if it is not working, shick it into the MYSQL Query Browser and see it it does the job there. I usually find this gives me some clues what I have done wrong. Quote Link to comment Share on other sites More sharing options...
gigas10 Posted July 6, 2008 Share Posted July 6, 2008 hmmm from some of the things that have thrown me off the in past, try this, i could be wrong but i think u need the single quotes in your post variable names $newContent = $_POST[content]; $newContent = addslashes($newContent); $Updatepage = $_GET[pageName]; CHANGE TO $newContent = $_POST['content']; $newContent = addslashes('$newContent'); $Updatepage = $_GET['pageName']; Quote Link to comment Share on other sites More sharing options...
garethhall Posted July 6, 2008 Author Share Posted July 6, 2008 I tried that and it made no difference. Quote Link to comment Share on other sites More sharing options...
ocpaul20 Posted July 6, 2008 Share Posted July 6, 2008 i know, try this. if ($var === FALSE) { // do something... } else { // do something else } You need to test for FALSE with 3x = it says so somewhere. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted July 6, 2008 Share Posted July 6, 2008 You are using the mysql_error() the your logic for your SELECT query, why not use it for the UPDATE query to get mysql to tell you why the query failed? Quote Link to comment 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.