Jump to content

[SOLVED] Help cant get MYSQL database to update


garethhall

Recommended Posts

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;

?>

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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'];

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.