Updating using forms

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
jquickuk
Forum Newbie
Posts: 3
Joined: Tue May 06, 2008 2:34 pm

Updating using forms

Post by jquickuk »

First I would like to say that i am a noivce trying to get a PHP MYSQL application working so sorry if i sound a little stupid.

I am trying to update fields in my database but im trying to use forms which all the data will populate within a form and when i click submit it creates a new record to show the current updated version and leave the old record as a modified one.

I have managed to do all the other pages but this one is an important one for me.

Any code sippets or links will be appercaited

Cheers
John
User avatar
Mini
Forum Newbie
Posts: 23
Joined: Mon Dec 04, 2006 4:39 am
Location: Netherlands

Re: Updating using forms

Post by Mini »

jquickuk
Forum Newbie
Posts: 3
Joined: Tue May 06, 2008 2:34 pm

Re: Updating using forms

Post by jquickuk »

Thats great, thank you mini. Never seen the INSERT INTO query.

What about populating it into a form so it can be edited for easy update.

I have the input form for creating a module so to be able to place the data into the form fields, make changes and update would be awesome.
hora
Forum Newbie
Posts: 9
Joined: Mon May 05, 2008 10:17 pm

Re: Updating using forms

Post by hora »

Well that would be just the reverse, get the info from mysql first, use SELECT x FROM, then store the data in variables. Then when you make the form, set the value tags equal to those variables.

Example:

$query = "SELECT x, y, z FROM database"
$res = mysql_query($query);
$row = mysql_fetch_assoc($res)
$x = $row['x'];
$y = $row['y'];
$z = $row['z'];

echo "<form action=\"file.php\">";
echo "<input type=\"text\" name=\"x\" value=\".$x."\"/>";
echo "</form>";

etc.
DeFacto
Forum Commoner
Posts: 37
Joined: Wed Apr 23, 2008 2:30 pm

Re: Updating using forms

Post by DeFacto »

connection to database

Code: Select all

 
<?php
$dbhost = 'localhost';
$dbuser = 'user_name';
$dbpass = 'password';
 
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
 
$dbname = 'database_name';
mysql_select_db($dbname);
?>
 
and check this out: Tutorials
Post Reply