RE: [PHP] help with ERROR!
| From: | Mark | Date: | Wed, 21 May 2003 13:13:03 +0000 |
| Subject: | RE: [PHP] help with ERROR! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-148413@lists.php.net to get a copy of this message | ||
I thought there was an issue using || rather than OR in this kind of
statement. Try
$query = mysql_query( $sql ) or die( "query failed" );
--- "Ford, Mike [LSS]" <M.Ford@lmu.ac.uk> wrote:
> > -----Original Message-----
> > From: Jay Blanchard [mailto:jay.blanchard@niicommunications.com]
> > Sent: 21 May 2003 12:34
> >
> > [snip]
> > I've already tried to help him with this privately. The odd part
> is
> > that mysql_query is returning true, not a resource, even
> > though it's a
> > select query.
> >
> > >This is my Code
> > >http://nopaste.php-q.net/15837
> > >
> > >
> > >This is My Error!
> > >-------------------
> > >Warning: mysql_result(): supplied argument is not a valid
> > MySQL result
> > >resource in
> /home/virtual/site12/fst/var/www/html/do_authuser.php on
> > >line 27 result fetch failed
> > [/snip]
> >
> > Line 27 is;
> > $password_from_db = mysql_result( $query, 0 ) or die( "result
> fetch
> > failed" );
> >
> > The query is;
> > $sql = "SELECT password FROM auth_users WHERE username =
> > '$_POST[username]'";
> >
> > First, the connection string to the database ( $query, 0 ). IHMO
> the
> > connection to the DB should be contained in a variable rather
> > than using
> > the integer to access the connection. It's coding preference
> > really, but
> > most would consider it cleaner.
>
> I don't believe coding preference has anything to do with it -- the
> result
> resource may be #Resource id 0 (or something like that) if you echo
> it, but
> that is very different from the integer 0. *Always* assign your
> result
> resource to a variable, and use that in subsequent database calls
> that
> require it.
>
> >
> > Second, the query. Try this....
> >
> > $sql = "SELECT password FROM auth_users WHERE username = '" .
> > $_POST['username'] . "' ";
> >
> > ....where the variable for the username is concated into the
> > query, and
> > the array identifier is in single quotes.
>
> That will produce an identical result -- this *is* a matter of
> coding
> preference. (The following is also the same, and is my personal
> preference:
>
> $sql = "SELECT password FROM auth_users WHERE username =
> '{$_POST['username']}'";
>
> ).
>
> Cheers!
>
> Mike
>
>
---------------------------------------------------------------------
> Mike Ford, Electronic Information Services Adviser,
> Learning Support Services, Learning & Information Services,
> JG125, James Graham Building, Leeds Metropolitan University,
> Beckett Park, LEEDS, LS6 3QS, United Kingdom
> Email: m.ford@lmu.ac.uk
> Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
=====
Mark Weinstock
mark_weinstock@yahoo.com
***************************************
You can't demand something as a "right" unless you are willing to fight to death to
defend everyone else's right to the same thing.
***************************************
__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com