Hello all, Long time reader, first time poster. I am getting several undefined offsets when I run my code here. I don't really understand why.

Below is the code and the output from the print_r's that I do to try to troubleshoot the missing offsets. I just am at a loss for what I am missing. Now if it was complaining about the offset being empty, thats one thing, but it is complaining that the offsets do not exist when clearly they do.

The PHP Errors below show that offsets 0 thru 2 can not be found, but the arrays tell a different story. Any ideas?

PHP ERRORS GENERATED:

Notice: Undefined offset: 0 in C:\htdocs\custaccess\scripts\functions.php on line 848

Notice: Undefined offset: 0 in C:\htdocs\custaccess\scripts\functions.php on line 849

Notice: Undefined offset: 0 in C:\htdocs\custaccess\scripts\functions.php on line 850

Notice: Undefined offset: 0 in C:\htdocs\custaccess\scripts\functions.php on line 851

Notice: Undefined offset: 0 in C:\htdocs\custaccess\scripts\functions.php on line 852

Notice: Undefined offset: 0 in C:\htdocs\custaccess\scripts\functions.php on line 853

Notice: Undefined offset: 0 in C:\htdocs\custaccess\scripts\functions.php on line 854

Notice: Undefined offset: 1 in C:\htdocs\custaccess\scripts\functions.php on line 848

Notice: Undefined offset: 1 in C:\htdocs\custaccess\scripts\functions.php on line 849

Notice: Undefined offset: 1 in C:\htdocs\custaccess\scripts\functions.php on line 850

Notice: Undefined offset: 1 in C:\htdocs\custaccess\scripts\functions.php on line 851

Notice: Undefined offset: 1 in C:\htdocs\custaccess\scripts\functions.php on line 852

Notice: Undefined offset: 1 in C:\htdocs\custaccess\scripts\functions.php on line 853

Notice: Undefined offset: 1 in C:\htdocs\custaccess\scripts\functions.php on line 854

Notice: Undefined offset: 2 in C:\htdocs\custaccess\scripts\functions.php on line 848

Notice: Undefined offset: 2 in C:\htdocs\custaccess\scripts\functions.php on line 849

Notice: Undefined offset: 2 in C:\htdocs\custaccess\scripts\functions.php on line 850

Notice: Undefined offset: 2 in C:\htdocs\custaccess\scripts\functions.php on line 851

Notice: Undefined offset: 2 in C:\htdocs\custaccess\scripts\functions.php on line 852

Notice: Undefined offset: 2 in C:\htdocs\custaccess\scripts\functions.php on line 853

Notice: Undefined offset: 2 in C:\htdocs\custaccess\scripts\functions.php on line 854

COUNT STRING VALUE AND ARRAY OUTPUT:

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] => ) )

GLOBAL $siteloc;
$count=$_GET['count'];

//Arrays passed as a post arrays and renamed removing the post superglobal
$id = array ("id"=>$_POST['id']);
$firstname =array ("firstname"=>$_POST['firstname']);
$lastname=array ("lastname"=>$_POST['lastname']);
$email=array("email"=>$_POST['email']);
$phonenum=array("phonenum"=>$_POST['phonenum']);
$faxnum=array("faxnum"=>$_POST['faxnum']);
$mobilenum=array("mobilenum"=>$_POST['mobilenum']);

//debug to see the arrays and make sure they are keyed right.
echo $count.'<P>';
print_r($id);
echo '<br>';
print_r($firstname);
echo '<br>';
print_r($lastname);
echo '<br>';
print_r($email);
echo '<br>';
print_r($phonenum);
echo '<br>';
print_r($faxnum);
echo '<br>';
print_r($mobilenum);




			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);
		  }
		

    oops $count=3, looks like I missed that on my cut and paste.

    Steve

      try wrapping the arrays in {} and your missing a ' before the WHERE

        no sure what your talking about by wrapping the arrays in {}, PHP throws an error with the below code because of unexpected '{'. Also thanks for the catch on the SQL query. I always miss those.

        $id = array {"id"=>$_POST['id']};

          I found my own problem, just do not know how to fix it. I've nested the arrays by trying to rename them. firstname = an array that contains values 0, 1, and 2. How to rename it without nesting it. Hrrrrrm.

          look at the array output:

          Array ( [firstname] => Array ( [0] => ZXCzxczxc [1] => dsfdfasdf [2] => 444444444444444 ) )

            Use the braces in the query
            and add the secondary array
            {
            $sql1="UPDATE customer_contact SET
            firstname='{$firstname['firstname'][$i]}', // example

              You should also use mysql_real_escape_string() on any data in the query.

                That was the solution. Thanks Halfabee

                  $mobilenum=$_POST['mobilenum'];
                  is what you need.

                    That returned an array as string error in PHP, that is what I tried first.

                      Write a Reply...