Jump to content

UPDATE not working


wrathican

Recommended Posts

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.';
	  };
	  ?>

 

Link to comment
https://forums.phpfreaks.com/topic/56274-update-not-working/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/56274-update-not-working/#findComment-278005
Share on other sites

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

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/56274-update-not-working/#findComment-278056
Share on other sites

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.