Go Back   Forum Care Forums > Development Reference Area > MySQL Discussion

Reply
 
LinkBack Thread Tools Display Modes
mysql_query("SELECT... / returned value
Old
  (#1)
sandison
Guest
 
Posts: n/a
Default mysql_query("SELECT... / returned value - 06-04-2007, 07:50 AM

Hi everyone !
I'm new to mysql/php and I'm building a small flash-based CMS.
For the login, I'm doing something like this:

$request=$_POST["request"];
$result=mysql_query($request, $db);
if ($result) echo tableToXml($result);

....where /request/ is POSTed from the flash and looks like this:

SELECT * FROM login WHERE username="testuser" AND p***word="testp***"

Strangely, it seems that even tho there aren't any "testuser" and "testp***"
in the database, $result is not returned as false. My tableToXml() function
is always executed. Any idea what's going on ? Help would be greatly
appreciated. Thanks !

sand.


   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: mysql_query("SELECT... / returned value
Old
  (#2)
Captain Paralytic
Guest
 
Posts: n/a
Default Re: mysql_query("SELECT... / returned value - 06-04-2007, 07:50 AM


sandison wrote:

> Hi everyone !
> I'm new to mysql/php and I'm building a small flash-based CMS.
> For the login, I'm doing something like this:
>
> $request=$_POST["request"];
> $result=mysql_query($request, $db);
> if ($result) echo tableToXml($result);
>
> ...where /request/ is POSTed from the flash and looks like this:
>
> SELECT * FROM login WHERE username="testuser" AND p***word="testp***"
>
> Strangely, it seems that even tho there aren't any "testuser" and "testp***"
> in the database, $result is not returned as false. My tableToXml() function
> is always executed. Any idea what's going on ? Help would be greatly
> appreciated. Thanks !
>
> sand.
>From the manual:

Return Values
Zero if the query was successful. Non-zero if an error occurred.

Whether a query returns 1 row, 200 rows or 0 rows, has no bearing on
its success or failure as a query.

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: mysql_query("SELECT... / returned value
Old
  (#3)
sandison
Guest
 
Posts: n/a
Default Re: mysql_query("SELECT... / returned value - 06-04-2007, 07:50 AM

Captain Paralytic wrote:
> sandison wrote:
>
>> Hi everyone !
>> I'm new to mysql/php and I'm building a small flash-based CMS.
>> For the login, I'm doing something like this:
>>
>> $request=$_POST["request"];
>> $result=mysql_query($request, $db);
>> if ($result) echo tableToXml($result);
>>
>> ...where /request/ is POSTed from the flash and looks like this:
>>
>> SELECT * FROM login WHERE username="testuser" AND p***word="testp***"
>>
>> Strangely, it seems that even tho there aren't any "testuser" and
>> "testp***" in the database, $result is not returned as false. My
>> tableToXml() function is always executed. Any idea what's going on ?
>> Help would be greatly appreciated. Thanks !
>>
>> sand.
>> From the manual:

> Return Values
> Zero if the query was successful. Non-zero if an error occurred.
>
> Whether a query returns 1 row, 200 rows or 0 rows, has no bearing on
> its success or failure as a query.


Ok thank you. I thought that 0 row would be interpreted as a failure.
++




   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: mysql_query("SELECT... / returned value
Old
  (#4)
Captain Paralytic
Guest
 
Posts: n/a
Default Re: mysql_query("SELECT... / returned value - 06-04-2007, 07:50 AM


sandison wrote:

> Captain Paralytic wrote:
> > sandison wrote:
> >
> >> Hi everyone !
> >> I'm new to mysql/php and I'm building a small flash-based CMS.
> >> For the login, I'm doing something like this:
> >>
> >> $request=$_POST["request"];
> >> $result=mysql_query($request, $db);
> >> if ($result) echo tableToXml($result);
> >>
> >> ...where /request/ is POSTed from the flash and looks like this:
> >>
> >> SELECT * FROM login WHERE username="testuser" AND p***word="testp***"
> >>
> >> Strangely, it seems that even tho there aren't any "testuser" and
> >> "testp***" in the database, $result is not returned as false. My
> >> tableToXml() function is always executed. Any idea what's going on ?
> >> Help would be greatly appreciated. Thanks !
> >>
> >> sand.
> >> From the manual:

> > Return Values
> > Zero if the query was successful. Non-zero if an error occurred.
> >
> > Whether a query returns 1 row, 200 rows or 0 rows, has no bearing on
> > its success or failure as a query.

>
> Ok thank you. I thought that 0 row would be interpreted as a failure.
> ++


The strange thing is that, ***uming this is php, then a 0 value is
interpreted as false. Thus I would expect your tableToXml() function to
NOT get executed if the query was good.

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: mysql_query("SELECT... / returned value
Old
  (#5)
Willem Bogaerts
Guest
 
Posts: n/a
Default Re: mysql_query("SELECT... / returned value - 06-04-2007, 07:50 AM

> $request=$_POST["request"];
> $result=mysql_query($request, $db);
> if ($result) echo tableToXml($result);
>
> ...where /request/ is POSTed from the flash and looks like this:
>
> SELECT * FROM login WHERE username="testuser" AND p***word="testp***"


You are aware that everyone could send any query (like DROP DATABASE
etc.) to your PHP page? I hope you check your input
>
> Strangely, it seems that even tho there aren't any "testuser" and "testp***"
> in the database, $result is not returned as false.


True. the function returns a resource if successful. Use
mysql_fetch_array() to get the rows.

Best regards

--
Willem Bogaerts

Application smith
Kratz B.V.
http://www.kratz.nl/
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: mysql_query("SELECT... / returned value
Old
  (#6)
sandison
Guest
 
Posts: n/a
Default Re: mysql_query("SELECT... / returned value - 06-04-2007, 07:50 AM

sandison wrote:
> Hi everyone !
> I'm new to mysql/php and I'm building a small flash-based CMS.
> For the login, I'm doing something like this:
>
> $request=$_POST["request"];
> $result=mysql_query($request, $db);
> if ($result) echo tableToXml($result);
>
> ...where /request/ is POSTed from the flash and looks like this:
>
> SELECT * FROM login WHERE username="testuser" AND p***word="testp***"
>
> Strangely, it seems that even tho there aren't any "testuser" and
> "testp***" in the database, $result is not returned as false. My
> tableToXml() function is always executed. Any idea what's going on ?
> Help would be greatly appreciated. Thanks !
>
> sand.


thanks all
I used if (mysql_num_rows($result)>0) ... to check the result and now it
works fine !



   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Contact Us - Forum Care Forums - Archive - Top