Re: [PHP] why won't my array work?



On Fri, Mar 28, 2008 at 12:28 PM, Jason Pruim <japruim@xxxxxxxxxx> wrote:
[snip!]

$oldpasswordquery = "SELECT loginPassword, Record FROM current WHERE
loginPassword='{$oldPassHash}' AND Record='{$Record}'";
$chpwold[] = mysqli_query($chpwpostlink, $oldpasswordquery) or
die("Sorry read failed: ". mysqli_error($chpwpostlink));
$chpwresult = $chpwold[0];
$chpwrow[] = mysqli_fetch_assoc($chpwresult) or die('Sorry it didn\'t
work....' .mysqli_error($chpwpostlink));
echo $chpwrow['loginPassword'];
print_r($chpwrow);


The echo and the print_r are for debugging and obviously wont' be in
the final script... Here is the error that I am getting:

[Fri Mar 28 12:14:39 2008] [error] PHP Notice: Undefined index:
loginPassword in /Volumes/RAIDer/webserver/Documents/dev/OLDBv2/admin/
chpwpost.php on line 18
[snip!]

Let's explain this a bit....

$chpwrow[] = mysqli_fetch_assoc($chpwresult) // ....

The response from mysqli_fetch_assoc() will be an array already.
You're then adding this into the $chpwrow[] array, which creates a
nested array. So to call it from your example, you'd need
$chpwrow[0]['loginPassword'].



--
</Daniel P. Brown>
Forensic Services, Senior Unix Engineer
1+ (570-) 362-0283
.