Link to home
Start Free TrialLog in
Avatar of Computer Guy
Computer Guy

asked on

Using PHP (example needed), how can I save fields on a form to a database

Can someone please provide me with an example with the following parameters?

I have a database named "SiteConfig" and a table called "configurations".
I have created the following fields in the "configurations" table:

- version
- helpdesk
- shopping_cart
- backup_server
- notes

-I need an example of a PHP page that can connect to a database
-A PHP page with the fields from the database:
  - The fields helpdesk, shopping_cart and backup_server are SELECT fields
  -  The field notes is a TEXT AREA field
  -  The field version is a TEXT BOX

I need this data to be populated in their specified areas when the page is loaded
I need an "update" button that will update the new values to the database
When this page is updated, I need a message "Variables have been updated"
Avatar of Lukasz Chmielewski
Lukasz Chmielewski
Flag of Poland image

Not tested. The select fields - you would have to tell what are the options for them

<?php
$link = mysql_connect("yourserver","youruser","yourpass") or die(mysql_error());
mysql_select_db(SiteConfig) or die(mysql_error());

if(!empty($_POST)){
 $version = $_POST[version];
 $notes = $_POST[notes];
 $helpdesk = $_POST[helpdesk];
 $shopping_cart = $_POST[shopping_cart];
 $backup_server = $_POST[backup_server];

 $query = "update configurations set version = '$version', notes = '$notes', helpdesk = '$helpdesk', shopping_cart = '$shopping_cart', backup_server = '$backup_server' ";
 $result = mysql_query($query) or die(mysql_error());

 echo"Record updated !";
}

$query = "select * from configurations";
$result = mysql_query($query) or die (mysql_error());
$row = mysql_fetch_row($result) or die(mysql_error());
?>

<form action="#" method="post">
<input type="textbox" name="version" value="<?php echo"$row[version]";?>" />
<textarea name="notes"><?php echo"$row[notes]";?></textarea>
<select name="helpdesk">
 -----------------
</select>
<select name="shopping_cart">
----------------
</select>
<select name="backup_server">
------------------
</select>
</form>

Open in new window

Avatar of Computer Guy
Computer Guy

ASKER

Can you please also include an update button
ASKER CERTIFIED SOLUTION
Avatar of Lukasz Chmielewski
Lukasz Chmielewski
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry for the cunfusion.