Page 1 of 1
update database information
Posted: Wed Sep 12, 2007 10:43 pm
by eeau1973
Hi ... maybe for many of you this is a simple issue, but not for me ...
I need to know how to update records using a web form (not using phpmyadmin or some kind of editor ). my database is created with mysql and i would like to use php ..
The user must look for a field defined and then if the user decide to change / update that record i must to show all the related information and then insert the new fields ...
thanks in advance for any help !
greetings ..
Posted: Wed Sep 12, 2007 11:12 pm
by elinews
Here's a helpful, and very visual tutorial:
http://www.spoono.com/php/tutorials/tutorial.php?id=23 -- There way is designed to all go on one page.
The main idea - to actually update the article:
$sql = "UPDATE whatever SET title='$title',content='$content',edit_date='NOW()' WHERE id=$edit_id";
Another way to grab the id:
Code: Select all
function get_id(){
$pattern = "/.*\/\w+.php.id.()/i";
$replacement = "\${1}";
$edit_id = preg_replace($pattern, $replacement, $_SERVER['REQUEST_URI']);
return $edit_id;
};
$edit_id = get_id();
This will make it so if
http://www.website.com/page.php?id=1 is visited, $edit_id will equal 1. then in the database connect just do "SELECT*, FROM whatever WHERE id='$edit_id'" Then if you make a form field value=$title it will display $title from row 1.
re: update record information ..
Posted: Wed Sep 12, 2007 11:23 pm
by eeau1973
Thanks for the tips .. but the address
http://www.spoono.com/php/tutorials/tutorial.php?id=23 is not working
Would you please letme know if is really correct the web site that you suggest ? ..
thanks again .. !
Posted: Wed Sep 12, 2007 11:27 pm
by elinews
hmm... very strange. It works for me in both of the posts. Try going to the link below and then click on Edit Row in Mysql in the right hand column. If that doesn't work then go to spoono.com > Programming > PHP > Tutorials (view all) > and then Edit row in mysql.
http://www.spoono.com/php/tutorials/
http://www.spoono.com/php/tutorials/