Jump to content

UPDATE from form data


Lodius2000

Recommended Posts

I am new to UPDATE query's this just looks a little funky to me

 

can you guys look it over and tell me if it's right

 

I want it to replace the field data in mysql with what is currently in the form

 

this function runs upon submission of a form and always says that Article body has been updated and prints the link back to managearticle/index.php, but nothing is modified, I have put TEST in both the title and article field and submit bit nothing happens in the DB, makes me think that my if() statements aren't working, I want it to check to see if the 2 fields, $title, $article are different, in content from the edited versions $edited_... and then run the if() if there has been a change

 

<?php
function process_form(){
global $db, $id, $title, $article;

$edited_title = mysql_real_escape_string($_POST['title']);
$edited_article = mysql_real_escape_string($_POST['body']);


//check to see if title has changed, if changed, update db
if ($title != $edited_title){

	$db->query("UPDATE text_cms SET article_title = '$edited_title' WHERE article_id = '$id'");
	print "Updated <strong>$title</strong> in the database.<br />\n";
}

//check to see if body has changed, if changed, update db
if ($article != $edited_article){
	$db->query("UPDATE text_cms SET article = '$edited_article' WHERE article_id = '$id'");
	print "Updated <strong>article body</strong> in the database.<br />\n";
}

print '<a href="../managearticle/index.php">Go back to article management</a>';


}
?>

 

 

Thanks so much

Link to comment
https://forums.phpfreaks.com/topic/109344-update-from-form-data/
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.