Re: why won't my array work?
| From: | Daniel Brown | Date: | Fri, 28 Mar 2008 17:27:16 +0000 |
| Subject: | Re: why won't my array work? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-272248@lists.php.net to get a copy of this message | ||
On Fri, Mar 28, 2008 at 12:28 PM, Jason Pruim <japruim@raoset.com> 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