Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #3870
| From | tony@mountifield.org (Tony Mountifield) |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Hmm..why doesnt this work? |
| Date | 2011-11-22 16:22 +0000 |
| Organization | Software Insight Ltd., Winchester, UK |
| Message-ID | <jagi7c$ath$1@softins.clara.co.uk> (permalink) |
| References | <jaghhf$867$1@news.albasani.net> |
In article <jaghhf$867$1@news.albasani.net>,
The Natural Philosopher <tnp@invalid.invalid> wrote:
>
>
> $old=(mysql_fetch_assoc(mysql_query(sprintf(
> "select login_name from employees where id='%d'",
> $_POST['id']))))['id'];
>
>
> Bitching about unexpected '['
>
> But mysql_fetch_assoc() returns an array so what's wrong with
>
> mysql_fetch_assoc()['id'];
Or even (mysql_fetch_assoc())['id'] :-)
Firstly, id isn't in the field list. Only login_name is. But that's
semantic, not syntax.
But you shouldn't dereference the return value of mysql_fetch_assoc()
without first checking it for success:
$res = mysql_fetch_assoc(mysql_query(sprintf(
"select login_name from employees where id=%d",
$_POST['id'])));
if ($res !== false) {
$old = $res['login_name'];
} else {
// handle the error, including checking mysql_error()
}
Cheers
Tony
--
Tony Mountifield
Work: tony@softins.co.uk - http://www.softins.co.uk
Play: tony@mountifield.org - http://tony.mountifield.org
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Hmm..why doesnt this work? The Natural Philosopher <tnp@invalid.invalid> - 2011-11-22 16:10 +0000
Re: Hmm..why doesnt this work? The Natural Philosopher <tnp@invalid.invalid> - 2011-11-22 16:19 +0000
Re: Hmm..why doesnt this work? tony@mountifield.org (Tony Mountifield) - 2011-11-22 16:22 +0000
Re: Hmm..why doesnt this work? The Natural Philosopher <tnp@invalid.invalid> - 2011-11-22 17:24 +0000
Re: Hmm..why doesnt this work? tony@mountifield.org (Tony Mountifield) - 2011-11-22 17:44 +0000
Re: Hmm..why doesnt this work? The Natural Philosopher <tnp@invalid.invalid> - 2011-11-22 17:49 +0000
Re: Hmm..why doesnt this work? The Natural Philosopher <tnp@invalid.invalid> - 2011-11-22 17:57 +0000
csiph-web