Solved

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

Posted on 2011-03-14
4
281 Views
Last Modified: 2013-12-13
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"
0
Comment
Question by:Computer Guy
  • 2
  • 2
4 Comments
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35132237
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

0
 
LVL 3

Author Comment

by:Computer Guy
ID: 35132265
Can you please also include an update button
0
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 500 total points
ID: 35132304
Right ! Sorry :) Mind that will not work as it needs the options between SELECTS

<?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>
<input type="submit" value="update" />
</form>

Open in new window

0
 
LVL 3

Author Comment

by:Computer Guy
ID: 35151621
Sorry for the cunfusion.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to use md5 hashing 3 29
Load google maps api into wordpress 5 38
WordPress syntax 2 28
javascript date picker in php while loop 5 28
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now