update database information

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eeau1973
Forum Commoner
Posts: 27
Joined: Sat Aug 19, 2006 4:49 pm

update database information

Post 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 ..
elinews
Forum Commoner
Posts: 38
Joined: Tue Aug 14, 2007 7:18 pm

Post 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.
eeau1973
Forum Commoner
Posts: 27
Joined: Sat Aug 19, 2006 4:49 pm

re: update record information ..

Post 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 .. !
elinews
Forum Commoner
Posts: 38
Joined: Tue Aug 14, 2007 7:18 pm

Post 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/
Post Reply