Go Back   Singapore Web Hosting Talk > TECHNICAL > Programming Forum

Programming Forum Web applications, languages and other related issues in configuration, optimization, practical usage and database connectivity.

Reply
 
Thread Tools
Old 22-07-2009, 03:23   #1
MumbleVoice-Jen
SGWHT Newbie
 
Join Date: 09-07-2009
Posts: 12
MumbleVoice-Jen is on a distinguished road
need help with php/mysql foreach loop

Hello,

I am having a problem I am hoping someone can help. I have used the below code before and had it working with no issues. However my issue right now is the below foreach loop is only inserting the first record into the mysql table and not all the values in the array. I have confirmed the two array has more then one value in them. Yes only the virst value from each array is being interested into mysql.


PHP Code:
here is my form 

<form method='POST' action='process.php'
shift <input type='hidden' name='shiftid[]' value='$shiftid'><br /> 
Your Rank <select name='shiftrank[]'><option value='1'>1</option><option value='2'>2</option
PHP Code:
foreach($_POST["shiftid"] AS $key => $val) {  
     
$shiftid $val
     
$shiftrank $_POST['shiftrank'][$key];      
       echo 
"shiftid is $shiftid and rank is $shiftrank<br />"
     
//$updatesql = mysql_query("INSERT into employee_shiftbids SET Shiftid='$shiftid', Shiftrank='$shiftrank', Bidstatus='sent', Employeerank='0'");                 
     

Also I know I should be using mysql_escape_string() on my $_POST data I took it out during trouble shooting so no need to point out about sql injection etc. So what is wrong with ym foreach loop ??
Thanks all for youre time and assistance
__________________
MumbleVoice.com - Providing Affordable & Reliable Mumble Voice Hosting Servers since 2001!
MumbleVoice-Jen is offline   Reply With Quote

Old 23-07-2009, 21:20   #2
ConceptLane
SGWHT Newbie
 
Join Date: 26-02-2008
Location: Singapore
Posts: 176
ConceptLane has a spectacular aura aboutConceptLane has a spectacular aura about
Have you tried echo'ing the mysql error after each mysql_query to see what the problem could be?
It sure looks like everything is correct, and if you are sure that the PHP script does see all the POSTed array members (i.e. that debug statement of echo'ing every id and rank is working), then it has to be a mysql issue.
Some key constraints perhaps?

By the way, I'd use

mysql_query("INSERT into employee_shiftbids(Shiftid, Shiftrank, Bidstatus, Employeerank) values('$shiftid', '$shiftrank', 'sent', '0')");
__________________
Roy Lee
ConceptLane Pte Ltd
Hosting, VPS, Colo, Dedi, Web Apps
ConceptLane is offline   Reply With Quote
Old 11-12-2013, 22:57   #3
chrisranjana
SGWHT Newbie
 
Join Date: 02-01-2003
Location: chennai, tamil nadu, India
Posts: 60
chrisranjana is on a distinguished road
Code:
 $shiftid = $val; 
     $shiftrank = $_POST['shiftrank'][$key];
Wouldn't $shiftid and $shiftrank be one and the same ?
__________________
Chris, Programmer/Developer, Chrisranjana.com,
Ruby on Rails Programmers,
Php laravel developers,
Chennai, Tamil Nadu, India.
http://www.chrisranjana.com
chrisranjana is offline   Reply With Quote
Reply

Thread Tools

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

Forum Jump




All times are GMT +8. The time now is 03:04.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright (C) 2002-2015 Brought to you by Singapore Web Hosting Talk (SGWHT). All Rights Reserved.