Current location: Hot Scripts Forums » Programming Languages » PHP » Updating Multiple Table Values w/ Post Data


Updating Multiple Table Values w/ Post Data

Reply
  #1 (permalink)  
Old 12-11-08, 12:46 PM
arcuivie arcuivie is offline
Newbie Coder
 
Join Date: Nov 2008
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Updating Multiple Table Values w/ Post Data

I'm trying to create sort of a CP for myself where I can update multiple table values through POST data. Basically I have a table on the page that displays all the information pulled from the table I'm editing, and each field is within an form input text box. Looks like this:

PHP Code:

    while ($part mysql_fetch_assoc($result2))

    {
$part_list .= "</tr><tr><td><input type=\"text\" name=\"apt\" size=\"5\" class=\"one\" value=\"" $part['apt'] . "\" /></td><td><input type=\"text\" name=\"apt_type\" size=\"15\" class=\"one\" value=\"" $part['apt_type'] . "\" /></td><td width=\"350\"><input type=\"text\" name=\"descript\" size=\"60\" class=\"one\" value=\""$part['descript'] ."\" /></td><td>"$part['reqdate'] ."</td><td>"$part['postdate'] ."</td><td><input type=\"text\" name=\"pending\" size=\"1\" class=\"one\" value=\""$part['pending'] ."\" /></td><td><input type=\"text\" name=\"invno\" size=\"10\" class=\"one\" value=\""$part['invno'] ."\" /></td><td><input type=\"text\" name=\"amount\" size=\"5\" class=\"one\" value=\""$part['amount'] ."\" /></td><td id=\"two\"><a href=\"lib/wkdltprq.php?woid=" $part['wo_id'] ."&type=delete\"><strong>Delete</strong></a></td></tr>";

This is just a snippet of code to show you how it's set up. So, I send this data to another file, which contains:

PHP Code:

$property $_GET['property'];

$invoiceno form($_POST['invno']);
$pending form($_POST['pending']);
$amount form($_POST['amount']);
$apt form($_POST['apt']);
$apt_type form($_POST['apt_type']);
$description form($_POST['descript']);

mysql_query("UPDATE `workorders` SET descript = '$description', invno = '$invoiceno', amount = '$amount', pending = '$pending' WHERE apt = '$apt' AND apt_type = '$apt_type'")
or die (
mysql_error());
header ("Location: ../invmanagement.php"); 
This would work fine if there was only 1 form I was working with, but with the way I have it set up I have 1 form with multiple same-named values, if that makes any sense. Anyway, how can I change my code so I can mass update what data is displayed on the table? While retaining values that weren't changed, of course.

Thanks a bunch!
Reply With Quote
  #2 (permalink)  
Old 12-11-08, 02:25 PM
DAL's Avatar
DAL DAL is offline
Code Master
 
Join Date: Jun 2003
Location: North East England/UK
Posts: 874
Thanks: 0
Thanked 0 Times in 0 Posts
use form arrays by naming your form inputs with [] on the end and then this will populate the $_POST results as an array;

PHP Code:

while ($part mysql_fetch_assoc($result2))
    {
$part_list .= "</tr><tr><td><input type=\"text\" name=\"apt[]\" size=\"5\" class=\"one\" value=\"" $part['apt'] . "\" /></td><td><input type=\"text\" name=\"apt_type\" size=\"15\" class=\"one\" value=\"" $part['apt_type'] . "\" /></td><td width=\"350\"><input type=\"text\" name=\"descript\" size=\"60\" class=\"one\" value=\""$part['descript'] ."\" /></td><td>"$part['reqdate'] ."</td><td>"$part['postdate'] ."</td><td><input type=\"text\" name=\"pending\" size=\"1\" class=\"one\" value=\""$part['pending'] ."\" /></td><td><input type=\"text\" name=\"invno\" size=\"10\" class=\"one\" value=\""$part['invno'] ."\" /></td><td><input type=\"text\" name=\"amount\" size=\"5\" class=\"one\" value=\""$part['amount'] ."\" /></td><td id=\"two\"><a href=\"lib/wkdltprq.php?woid=" $part['wo_id'] ."&type=delete\"><strong>Delete</strong></a></td></tr>";

__________________
"once upon a midnight dreary, while i pron surfed, weak and weary, over many a strange and spurious site of 'hot xxx galore'. While i clicked my fav'rite bookmark, suddenly there came a warning, and my heart was filled with mourning, mourning for my dear amour," 'Tis not possible!", i muttered, "give me back my free hardcore!" quoth the server, 404."
Reply With Quote
  #3 (permalink)  
Old 12-11-08, 02:27 PM
arcuivie arcuivie is offline
Newbie Coder
 
Join Date: Nov 2008
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Ah, thanks a bunch! Do I need to change anything within the mysql query? Or will it be able to pick and choose the way it is?
Reply With Quote
  #4 (permalink)  
Old 12-11-08, 02:34 PM
DAL's Avatar
DAL DAL is offline
Code Master
 
Join Date: Jun 2003
Location: North East England/UK
Posts: 874
Thanks: 0
Thanked 0 Times in 0 Posts
I think you would just need to experiment with the values, PHP does some neat tricks when working with this kind of thing as far as I've experienced but I would always check to see what values are coming through from what scenarios.

It's easy to check;

PHP Code:

echo $property $_GET['property']."<br>";
echo 
$invoiceno form($_POST['invno'])."<br>";
echo 
$pending form($_POST['pending'])."<br>";
echo 
$amount form($_POST['amount'])."<br>";
echo 
$apt form($_POST['apt'])."<br>";

foreach(
$_POST['apt'] as $val){
     if(
$val != "") echo " -- ".$val."<br>";
}

echo 
$apt_type form($_POST['apt_type'])."<br>";
echo 
$description form($_POST['descript'])."<br>";

//oops forgot this;
echo $SQL_query "UPDATE `workorders` SET descript = '$description', invno = '$invoiceno', amount = '$amount', pending = '$pending' WHERE apt = '$apt' AND apt_type = '$apt_type'";
// mysql_query($SQL_query) or die (mysql_error());
//header ("Location: ../invmanagement.php"); 
__________________
"once upon a midnight dreary, while i pron surfed, weak and weary, over many a strange and spurious site of 'hot xxx galore'. While i clicked my fav'rite bookmark, suddenly there came a warning, and my heart was filled with mourning, mourning for my dear amour," 'Tis not possible!", i muttered, "give me back my free hardcore!" quoth the server, 404."
Reply With Quote
  #5 (permalink)  
Old 12-11-08, 02:39 PM
arcuivie arcuivie is offline
Newbie Coder
 
Join Date: Nov 2008
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks again DAL, this is going to help a lot.
Reply With Quote
  #6 (permalink)  
Old 12-11-08, 02:58 PM
DAL's Avatar
DAL DAL is offline
Code Master
 
Join Date: Jun 2003
Location: North East England/UK
Posts: 874
Thanks: 0
Thanked 0 Times in 0 Posts
no problem - best of luck

Cheers
Dal
__________________
"once upon a midnight dreary, while i pron surfed, weak and weary, over many a strange and spurious site of 'hot xxx galore'. While i clicked my fav'rite bookmark, suddenly there came a warning, and my heart was filled with mourning, mourning for my dear amour," 'Tis not possible!", i muttered, "give me back my free hardcore!" quoth the server, 404."
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with mysql selecting comparing values betweren more than a table Patbenavente PHP 0 08-19-08 06:34 PM
updating a table - php Dangar PHP 3 03-28-08 04:19 AM
[SOLVED] Storing multiple values in the same field Jay6390 Database 4 03-13-08 09:09 PM
mysql...post to table creepycridler PHP 5 03-23-05 12:12 AM
Expire table data? bobby444 PHP 1 09-22-04 08:14 AM


All times are GMT -5. The time now is 08:25 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.