Current location: Hot Scripts Forums » Programming Languages » PHP » UPDATE mysql from multiple POST rows


UPDATE mysql from multiple POST rows

Reply
  #1 (permalink)  
Old 01-17-06, 04:45 AM
wwanthony wwanthony is offline
Newbie Coder
 
Join Date: Jan 2005
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy UPDATE mysql from multiple POST rows

Hi,
I have a script that selects data from mysql and echos the data in a table in input boxes ready to edit. The problem i'm having is that as there is multiple rows with one submit button, only the first row is being updated.

PHP Code:

if ($_POST[CALL] == 1){

while (
$i 11) {
$call $_POST['del'.$i];
if (
$call) {
$query mysql_query("UPDATE ning SET Date='$Date', mer='$mer', Mae='$Mae', Technician='$Technician', Ord='$Ord', 
Post_Code='
$Post_Code',  Act='$Act', Phone_Number='$Phone_Number', Numb='$Numb', Type='$Type', Comments='$Comments', 
Called='1' WHERE PDIID=
$jobID");

    
header("Location: Call.php?status=Success");
}
  }
$i++;

The script above is where the fields to update the input box rows from the posted page. (what a mouthful???)
Please could anyone offer some advice as it surely must be just as easy to UPDATE multiple rows as it is to fetch multiple rows?

Best Regards,
Anthony
Reply With Quote
  #2 (permalink)  
Old 01-19-06, 07:05 PM
Patiek Patiek is offline
Wannabe Coder
 
Join Date: Nov 2003
Posts: 165
Thanks: 0
Thanked 0 Times in 0 Posts
The reason only the first row is being update, I think, is because you have the following:

PHP Code:

header("Location: Call.php?status=Success"); 

being called after the first mysql_query();

Thus, your script goes like this:

while
{
update_mysql;
redirect_to_another_page; die();
}

You need to put that header("Location...") outside of your loop.

And yes, you can update multiple rows in one query and you can optimize that query in various ways... but a lot of that is dependent on what you are updating / how you are updating / values you are placing.
Reply With Quote
  #3 (permalink)  
Old 01-19-06, 07:34 PM
wwanthony wwanthony is offline
Newbie Coder
 
Join Date: Jan 2005
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Hi Patiek,
Thankyou for your reply, I thoroughly appreciate your help.

I can clearly see now that the forward shouldnt have been there and it should be outside of the loop.

Another thing I was wondering before i've actually tried it is:

I have put a checkbox for the rows to be selected for deletion in the form to be POST to this multiple delete or update script, I was wondering how should I name those checkboxes? I have put an $i increment so each rows checkbox would be named del1 del2 del3 etc etc. as you can see from the cod snippet I have tried to incorporate that in $call.

Would that be successful, other than it wouldnt be if there were more then 11 rows?

Hope i'm making sense, its just I dont completely understand it myself

Thankyou once again for your help.
Reply With Quote
  #4 (permalink)  
Old 01-20-06, 03:56 AM
wwanthony wwanthony is offline
Newbie Coder
 
Join Date: Jan 2005
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Hi,
just tried it with:

}
$i++;
}
header("Location: CallOff.php"."$values");
}

It still just updates the first row?
Any further guidance would be most appreciated.
Reply With Quote
  #5 (permalink)  
Old 01-20-06, 06:48 AM
Oras Oras is offline
Newbie Coder
 
Join Date: Jan 2006
Location: Baghdad, Iraq
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Hi,
can you tell me what $jobID is? you said you have 11 rows of data, so there should be different $jobID for each one isn't it?
__________________
e-Haw!
Reply With Quote
  #6 (permalink)  
Old 01-20-06, 08:14 AM
wwanthony wwanthony is offline
Newbie Coder
 
Join Date: Jan 2005
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Hi Oras,
Yes jobID is the row ID for each job, each are unique.

Thanks for your interest.
Reply With Quote
  #7 (permalink)  
Old 01-20-06, 08:47 AM
Oras Oras is offline
Newbie Coder
 
Join Date: Jan 2006
Location: Baghdad, Iraq
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
This the point, you are using the same JobID in the loop, I can't see any change happen to it through the loop, that's why you are getting only the first row updated
__________________
e-Haw!
Reply With Quote
  #8 (permalink)  
Old 01-20-06, 01:16 PM
wwanthony wwanthony is offline
Newbie Coder
 
Join Date: Jan 2005
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Hi Oras,
I have a different jobID send with a hidden input from the posted form on each row, how would I get the UPDATE query to recognise each individual jobID?

Thanks again.
Reply With Quote
  #9 (permalink)  
Old 01-20-06, 01:28 PM
Oras Oras is offline
Newbie Coder
 
Join Date: Jan 2006
Location: Baghdad, Iraq
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Can you please put the source of your form here?
__________________
e-Haw!
Reply With Quote
  #10 (permalink)  
Old 01-21-06, 09:02 AM
wwanthony wwanthony is offline
Newbie Coder
 
Join Date: Jan 2005
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Hi Oras,
I'll have to wait till monday to get the source, was hoping to find a solution before then but i'll get back to you on monday.

Thanks very much.
Anthony
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
Problem with a mysql table update lppa2004 PHP 2 12-24-05 05:11 AM
UPDATE: MySQL Auto Backup & Export v1.1 Beyonder General Advertisements 2 03-21-05 02:05 PM
Multiple form fields saved in one mysql field?? cebuy PHP 4 10-15-04 12:08 PM
Help with multipart update form into MySQL DB... jimb575 PHP 0 07-01-04 02:42 PM
can't edit multiple rows at the same time conundrum PHP 2 04-01-04 12:50 AM


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