Current location: Hot Scripts Forums » Programming Languages » PHP » stuck on updating multiple records


stuck on updating multiple records

Reply
  #1 (permalink)  
Old 05-18-04, 09:26 PM
us0r us0r is offline
Newbie Coder
 
Join Date: May 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
stuck on updating multiple records

ok so I got this far but I'm not sure how I can update all rows of my query.

What I am trying to do is display customer names, product and price then have the option of putting in the USPS tracking number into a field I set up and click submit and update all records.

Here is what I got so far (and it works - just need to know how I can update all records):

<form method="POST" action="enterr.php">
<?php
mysql_connect("0.0.0.0", "orders", "programmingtalk", "orders")
or die("Could not connect: " . mysql_error());
mysql_select_db("orders");
$sql = ("SELECT first_name, last_name, product, cost FROM rkl_orders WHERE STATUS='1'");
$result = mysql_query($sql)
or die ("Could not do query: " . mysql_error());
while ($row = mysql_fetch_array ($result)) {
print("<tr><td>" . $row["first_name"] . " " . $row["last_name"] . "</td><td>RKL</td><td>" . $row["cost"] . "</td><td><input type=\"hidden\" name=\"name\" value=\"" . $row["first_name"] . " " . $row["last_name"] . "\"><input type=\"text\" name=\"track\" size=\"20\"></td></tr>");
}
mysql_close();
?>

I was going to use the hidden text box "name" and then update the "track" tabel in the DB where name = name.

I think I need to array this somehow any help would be greatly appreciated.

Thanks,
Ryan
Reply With Quote
  #2 (permalink)  
Old 05-18-04, 10:57 PM
Marshall Marshall is offline
Newbie Coder
 
Join Date: May 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
You could do something like
PHP Code:

UPDATE tablename SET track={$_POST['track']} WHERE first_name={$_POST['name']}; 

for the query to update the tables track id using the username.
Reply With Quote
  #3 (permalink)  
Old 05-19-04, 12:05 AM
us0r us0r is offline
Newbie Coder
 
Join Date: May 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
nice!

I'll give it a try thanks!
Reply With Quote
  #4 (permalink)  
Old 05-19-04, 01:09 AM
us0r us0r is offline
Newbie Coder
 
Join Date: May 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
it is only taking the last record.

any ideas?
Reply With Quote
  #5 (permalink)  
Old 05-19-04, 01:09 AM
Marshall Marshall is offline
Newbie Coder
 
Join Date: May 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
One recommendation though, assign userid #'s to people because if 2 people have the same first or last name it may get confused with which one it should choose, but if u have the people numbered u can refer to them by number and update it by number. Then you just have to associate that number with the login name and password so that when they login it can tell what their number is for table updating.


edit: If you need it to update multiple ones at the same time, you can do
PHP Code:

UPDATE tablename SET track={$_POST['track']}, name={$_POST['name'WHERE first_name(or userid)={$_POST['name']} 


Last edited by Marshall; 05-19-04 at 01:15 AM.
Reply With Quote
  #6 (permalink)  
Old 05-20-04, 05:33 PM
us0r us0r is offline
Newbie Coder
 
Join Date: May 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
ok I think I got it but it will only update the last record in the select.

any ideas?
Reply With Quote
  #7 (permalink)  
Old 05-20-04, 11:19 PM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Hi there,

I think the problem is that you have the same field names across all the records (i.e. "name" and "track" for each record's "name" and "track").

Try using arrays (i.e. "track[]" and "name[]") as field names if you have more than one pair, then loop through the POST vars to UPDATE each record.

My 2 cents.
__________________
Blavv =|
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! urgent.. how to select next 50 records? angela ASP 3 04-24-04 12:58 PM
Updating Mulltiple Tables JoJo26 PHP 8 04-21-04 04:05 PM
question about updating a page or database for an, php and mysql updating mikewooten PHP 1 02-12-04 12:11 AM
Create a next page link when there are too many records to be display in a webpage Han84 ASP 0 10-19-03 10:32 PM
getting -2147217900 error while inserting and updating skchakri ASP 3 09-20-03 10:34 AM


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