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
Updating using forms
Moderator: General Moderators
Re: Updating using forms
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.
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
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.
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
connection to database
and check this out: Tutorials
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);
?>