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;

?>

 

 

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.