/    Sign up×
Community /Pin to ProfileBookmark

Php for loop problem

Hello all, I havent been around here for awhile, but thought I would pop my head in. I’m running into a problem where I keep getting an unknown offset error in my code. Now I do a print_r on my arrays and I see the offsets there, so I am not sure why PHP is complaining and why my script isnt working. So, any help would be appreciated.

[CODE]FOR ($i=0;$i<$count;$i++)
{
$sql1=”UPDATE customer_contact SET
firstname=’$firstname[$i]’,
lastname=’$lastname[$i]’,
phonenum=’$phonenum[$i]’,
mobilenum=’$mobilenum[$i]’,
email=’$email[$i]’,
faxnum=’$faxnum[$i]
WHERE id=’$id[$i]'”;

$result1=mysql_query($sql1);
}[/CODE]

So above is the code causing the issue. Pretty simple stuff really.

Here are the arrays shown in Print_R format.

[CODE]
Array ( [id] => Array ( [0] => 7 [1] => 8 [2] => 9 ) )
Array ( [firstname] => Array ( [0] => ZXCzxczxc [1] => dsfdfasdf [2] => 444444444444444 ) )
Array ( [lastname] => Array ( [0] => xzxcz [1] => asdfsadfsdf [2] => 333333333333333333 ) )
Array ( [email] => Array ( [0] => zczxc [1] => asdfdsf [2] => 222222222222 ) )
Array ( [phonenum] => Array ( [0] => zcxzxczxc [1] => asdfsdf [2] => 1111111111111111111 ) )
Array ( [faxnum] => Array ( [0] => [1] => [2] => ) )
Array ( [mobilenum] => Array ( [0] => [1] => [2] => ) )[/CODE]

The Value of $count is 3

And the errors, PHP executes the FOR loop until $count is reached and then it ends, the problem is that it doesnt seem to recognize that the offsets in the arrays. Any help?:

Notice: Undefined offset: 0 in C:htdocscustaccessscriptsfunctions.php on line 848

Notice: Undefined offset: 0 in C:htdocscustaccessscriptsfunctions.php on line 849

Notice: Undefined offset: 0 in C:htdocscustaccessscriptsfunctions.php on line 850

Notice: Undefined offset: 0 in C:htdocscustaccessscriptsfunctions.php on line 851

Notice: Undefined offset: 0 in C:htdocscustaccessscriptsfunctions.php on line 852

Notice: Undefined offset: 0 in C:htdocscustaccessscriptsfunctions.php on line 853

Notice: Undefined offset: 0 in C:htdocscustaccessscriptsfunctions.php on line 854

Notice: Undefined offset: 1 in C:htdocscustaccessscriptsfunctions.php on line 848

Notice: Undefined offset: 1 in C:htdocscustaccessscriptsfunctions.php on line 849

Notice: Undefined offset: 1 in C:htdocscustaccessscriptsfunctions.php on line 850

Notice: Undefined offset: 1 in C:htdocscustaccessscriptsfunctions.php on line 851

Notice: Undefined offset: 1 in C:htdocscustaccessscriptsfunctions.php on line 852

Notice: Undefined offset: 1 in C:htdocscustaccessscriptsfunctions.php on line 853

Notice: Undefined offset: 1 in C:htdocscustaccessscriptsfunctions.php on line 854

Notice: Undefined offset: 2 in C:htdocscustaccessscriptsfunctions.php on line 848

Notice: Undefined offset: 2 in C:htdocscustaccessscriptsfunctions.php on line 849

Notice: Undefined offset: 2 in C:htdocscustaccessscriptsfunctions.php on line 850

Notice: Undefined offset: 2 in C:htdocscustaccessscriptsfunctions.php on line 851

Notice: Undefined offset: 2 in C:htdocscustaccessscriptsfunctions.php on line 852

Notice: Undefined offset: 2 in C:htdocscustaccessscriptsfunctions.php on line 853

Notice: Undefined offset: 2 in C:htdocscustaccessscriptsfunctions.php on line 854

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@ratcatemeNov 13.2008 — what are you print_ring

are you going
[code=php]print_r($some_array);
$id = $some_array['id'];
$firstname = $some_array['firstname'];
.....[/code]

??

why dint you just go
[code=php]$sql1="UPDATE customer_contact SET
firstname='{$some_array['firstname'][$i]}',
lastname='{$some_array['lastname'][$i]}',
phonenum='{$some_array['phonenum'][$i]}',
mobilenum='{$some_array['mobilenum'][$i]}',
email='{$some_array['email'][$i]}',
faxnum='{$some_array['faxnum'][$i]}',

WHERE id='{$some_array['id'][$i]}'";
[/code]


Scott.
Copy linkTweet thisAlerts:
@stevehaauthorNov 13.2008 — That is exactly what I did to fix it. Thank you for the help, just figured it out a few minutes ago myself.
×

Success!

Help @steveha spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...