Page 1 of 1

Updating using forms

Posted: Tue May 06, 2008 2:39 pm
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

Re: Updating using forms

Posted: Tue May 06, 2008 3:04 pm
by Mini

Re: Updating using forms

Posted: Tue May 06, 2008 3:11 pm
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.

Re: Updating using forms

Posted: Tue May 06, 2008 4:38 pm
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.

Re: Updating using forms

Posted: Wed May 07, 2008 3:19 am
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