I have arrays set up in a user form. One type is from
a multi-select list. (I'm passing these through a
multi page form as session variables)
The multi select list array code is like this:
To $_POST (going on to next page)I have this:
$_SESSION['industry'] = $_POST['L_Industry'];
Then in the final page where the database insert takes
place:
if ( is_array($_SESSION['industry'] ) ) {
foreach ($_SESSION['industry'] as $p ) {
$query = "INSERT INTO Prof_Industries (ProfID, IndID)
VALUES ('$LID', '$p')";
$res4 = run_query($query);
This seems to work just fine as the printout(echo) :
INSERT INTO Prof_Industries (ProfID, IndID) VALUES
('118', '1')
NOW here is the problem:
I have 3 textfield elements all named school[]
To post those:
$_SESSION['schools'] = $_POST['school'];
Then in preparation for insert:
if ( is_array($_SESSION['schools'] ) ) {
foreach($_SESSION['schools'] as $h) {
$query = "INSERT INTO Prof_Schools (ProfID, School)
VALUES ('$LID', '$h')";
$res6 = run_query($query);
echo $query;
}
}
But here is the problem, it seems if the user didn't
input on all 3 textfields the query fails, because the
array is printing out like this:
INSERT INTO Profiles_Schools (ProfID, School)
VALUES ('118', 'Baruch')
INSERT INTO Profiles_Schools (ProfID, School)
VALUES ('118', '')
INSERT INTO Profiles_Schools (ProfID, School) VALUES
('118', '')
So you see there is no value for 2 and 3 as the user
didn't input. But the array moves through the
elements anyway as the ProfID is assigned in the
query.
1-I guess I need a way to make sure in the foreach
that when the first empty element is reached the loop
dies.
2- Why would the second array behave differently then
the first ?
Stuart
Sorry for the long post. Just wanted to makre sure it
was clear in details.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php