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