FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Hmm..why doesnt this work?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Hmm..why doesnt this work? [message #176076 is a reply to message #176074] Tue, 22 November 2011 16:22 Go to previous messageGo to previous message
tony is currently offline  tony
Messages: 19
Registered: December 2010
Karma:
Junior Member
In article <jaghhf$867$1(at)news(dot)albasani(dot)net>,
The Natural Philosopher <tnp(at)invalid(dot)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(at)softins(dot)co(dot)uk - http://www.softins.co.uk
Play: tony(at)mountifield(dot)org - http://tony.mountifield.org
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: How to get client mac address in PHP ..?
Next Topic: Thumbnails with PHP
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Mon Nov 25 18:17:04 GMT 2024

Total time taken to generate the page: 0.07114 seconds