Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-03-14
4
Medium Priority
?
306 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

610 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