Professional Web Applications Themes

mysql_query("SELECT... / returned value - MySQL

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 password="testpass" Strangely, it seems that even tho there aren't any "testuser" and "testpass" 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....

  1. #1

    Default mysql_query("SELECT... / returned value

    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 password="testpass"

    Strangely, it seems that even tho there aren't any "testuser" and "testpass"
    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.


    sandison Guest

  2. #2

    Default Re: mysql_query("SELECT... / returned value


    sandison wrote:
     
    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.

    Captain Guest

  3. #3

    Default Re: mysql_query("SELECT... / returned value

    Captain Paralytic wrote: 
    > 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.[/ref]

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




    sandison Guest

  4. #4

    Default Re: mysql_query("SELECT... / returned value


    sandison wrote:
     
    > > 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.[/ref]
    >
    > Ok thank you. I thought that 0 row would be interpreted as a failure.
    > ++[/ref]

    The strange thing is that, assuming 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.

    Captain Guest

  5. #5

    Default Re: mysql_query("SELECT... / returned value

    > $request=$_POST["request"]; 

    You are aware that everyone could send any query (like DROP DATABASE
    etc.) to your PHP page? I hope you check your input 

    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/
    Willem Guest

  6. #6

    Default Re: mysql_query("SELECT... / returned value

    sandison wrote: 

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


    sandison Guest

Similar Threads

  1. "graphic select" vs "image select"
    By Gary_A.@adobeforums.com in forum Adobe Acrobat Windows
    Replies: 5
    Last Post: May 21st, 02:39 PM
  2. Using PHP to Print SELECT Results - Incomplete Data Returned
    By Keith W. McCammon in forum PHP Development
    Replies: 5
    Last Post: November 13th, 07:39 PM
  3. reuse mysql_query("SELECT..")
    By Stefan Fredriksson in forum PHP Development
    Replies: 6
    Last Post: November 12th, 04:01 PM
  4. limiting rows returned in a sql select
    By Lennart Jonsson in forum IBM DB2
    Replies: 2
    Last Post: August 26th, 03:41 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139