Results 1 to 12 of 12
  1. #1
    Join Date
    Dec 2008
    Posts
    30

    Unanswered: Warning: mysql_num_rows

    hello
    i need help with this error :

    Warning: mysql_num_rows(): supplied resource is not a valid MySQL result resource in /xxxx/xxxx/xxxx
    comprueba.php on line 20
    i have insert information to db and tables with this connection and this works fine.

    capture picture from my db here:

    http://www.busca.se/1.jpg
    http://www.busca.se/2.jpg
    http://www.busca.se/3.jpg

    <?php

    $mysql_host="xxxx.xxxxxx.xxxx";
    $mysql_user="anuncios";
    $mysql_password="xxxxxxx";
    $mysql_db = "suecia";

    $conn = mysql_connect("$mysql_host","$mysql_user","$mysql_ password")
    or die("Could not connect : " . mysql_error());

    mysql_select_db("$mysql_db",$conn)

    or die("Select database failed");

    $code = mysql_query("Select * from jos_call where code = '".@$_REQUEST['nombre']."'",@$conn);

    if (mysql_num_rows($conn)==0){ //error here//

    echo @$_REQUEST['nombre'].' - Codigo correcto';

    }else{

    echo @$_REQUEST['nombre'].' - Codigo falso';

    mysql_close($conn);
    }

    ?> <?php

    $mysql_host="xxxx.xxxxxx.xxxx";
    $mysql_user="anuncios";
    $mysql_password="xxxxxxx";
    $mysql_db = "suecia";

    $conn = mysql_connect("$mysql_host","$mysql_user","$mysql_ password")
    or die("Could not connect : " . mysql_error());

    mysql_select_db("$mysql_db",$conn)

    or die("Select database failed");

    $code = mysql_query("Select * from jos_call where code = '".@$_REQUEST['nombre']."'",@$conn);

    if (mysql_num_rows($conn)==0){ //error here//

    echo @$_REQUEST['nombre'].' - Codigo correcto';

    }else{

    echo @$_REQUEST['nombre'].' - Codigo falso';

    mysql_close($conn);
    }

    ?>

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    for whats its worth
    Code:
    $code = mysql_query("Select * from jos_call where code = '".@$_REQUEST['nombre']."'",@$conn);
    ...looks suspect to me

    Code:
    $code = mysql_query("Select * from jos_call where code = '".$_REQUEST['nombre']."'");
    looks reasonable, unless $_REQUEST['nombre'] is a number in which case you don't need the ' encapsualting the value.. in which case

    Code:
    $code = mysql_query("Select * from jos_call where code = ".$_REQUEST['nombre'].";");
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Dec 2008
    Posts
    30
    hi

    yes the are values and i have tested with your suggestion
    but i have received the same error .

    Warning: mysql_num_rows(): supplied resource is not a valid MySQL result resource in /public_html/viviendax2/ok/comprueba.php on line 18

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    oK so reasons for that problem...
    usually you have supplied an invalid or corrupt connection, as the connection or link identifier is optional try
    Code:
    $code = mysql_query("Select * from jos_call where code = '".@$_REQUEST['nombre']."';");
    incidentally I find it easier to debug SQL by assigning the SQL to a variable and then running the query.. the reason.. if you have SQL problems you can debug (view the SQL) before its sent to the SQL engine, and actaully see what is sent to the SQL engine, rather than what you think is being sent tot the SQL engine.

    so I'd suggest in future something like...
    Code:
    $sql = "Select * from jos_call where code = '".@$_REQUEST['nombre']."';";
    $code = mysql_query($sql) or die (echo "failed to open recordset, MySQL whinged pathetically:".mysql_errno().": ".mysql_error());
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Dec 2008
    Posts
    30

    error sqlquery empty

    hello

    error, my sql query is empty ,i am not sure self if this line is right after where

    $code = mysql_query("Select code from jos_call where code = ".@$_REQUEST['nombre'].";",@$conn);

    the tables name is jos_call
    in the tables the are 4 fields
    PAYNR
    CUSTNR
    CODE
    TAX

    when the user type the numbers in the text field the script must found the same number in the field code in the tables jos_call if this found the same number show in the label your code is right..

    capture picture from my db :

    http://www.busca.se/1.jpg
    http://www.busca.se/2.jpg
    http://www.busca.se/3.jpg

  6. #6
    Join Date
    Dec 2008
    Posts
    30

    syntax error

    when i add this line comming up this error

    <b>Parse error</b>: syntax error, unexpected T_ECHO in /public_html

    /viviendax2/ok/comprueba.php</b> on line <b>24</b><br />



    $code = mysql_query($sql) or die (echo "failed to open recordset, MySQL whinged pathetically:".mysql_errno().": ".mysql_error());

  7. #7
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    where is the @$conn); coming from, either remove the @ or remove the phrase
    option A
    $code = mysql_query("Select code from jos_call where code = ".@$_REQUEST['nombre'].";",$conn);
    option B
    $code = mysql_query("Select code from jos_call where code = ".@$_REQUEST['nombre'].";");

    option C
    $sql = Select code from jos_call where code = ".@$_REQUEST['nombre'].";";
    echo "my SQL is:".$sql;
    $code = mysql_query($sql);

    I have never seen the @ symbol used in this context
    it is used to suppress error messages
    eg $Result = @mysql_query($mySQL);

    the error that is now being reported is means there is a screw up in the or die message.. which doesn't surprise me as the code was created on the fly, culled from my generic error handlers
    I'd rather be riding on the Tiger 800 or the Norton

  8. #8
    Join Date
    Dec 2008
    Posts
    30

    error ......

    The are same error with or without @




    Option A and Option B the same error:


    La consulta fail: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #2' at line 1

    <?php

    $mysql_host="xxxx.xxxxxx.com";
    $mysql_user="anuncios";
    $mysql_password="xxxxxxx";
    $mysql_db = "suecia";
    $conn = mysql_connect("$mysql_host", "$mysql_user" , "$mysql_password")
    or die("Could not connect : " . mysql_error());
    mysql_select_db("$mysql_db",$conn)
    or die("Select database failed");

    $code = mysql_query("Select code from jos_call where code = ".@$_REQUEST['nombre'].";",@$conn);
    $resultado = mysql_query($code) or die('La consulta fail: ' . mysql_error());

    if (mysql_num_rows($conn)==0){
    echo @$_REQUEST['nombre'].' - Codigo correcto';
    }else{
    echo @$_REQUEST['nombre'].' - Codigo falso';
    mysql_close($conn);
    }
    ?>


    Option C:

    500 internal server error

    Parse error</b>: syntax error, unexpected T_STRING in /public_html

    comprueba.php</b> on line <b>13</b><br />


    <?php

    $mysql_host="xxxx.xxxx.com";
    $mysql_user="anuncios";
    $mysql_password="xxxxxxx";
    $mysql_db = "suecia";
    $conn = mysql_connect("$mysql_host", "$mysql_user" , "$mysql_password")
    or die("Could not connect : " . mysql_error());
    mysql_select_db("$mysql_db",$conn)
    or die("Select database failed");

    $sql = Select code from jos_call where code = ".@$_REQUEST['nombre'].";";
    echo "my SQL is:".$sql;
    $code = mysql_query($sql);

    $resultado = mysql_query($code) or die('La consulta fail: ' . mysql_error());

    if (mysql_num_rows($conn)==0){
    echo @$_REQUEST['nombre'].' - Codigo correcto';
    }else{
    echo @$_REQUEST['nombre'].' - Codigo falso';
    mysql_close($conn);
    }
    ?>

  9. #9
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    OK so I'd suggest you remove the quote marks on the connection and select db statements
    $conn = mysql_connect($mysql_host, $mysql_user , $mysql_password) or die("Could not connect : ".mysql_error());
    mysql_select_db($mysql_db,$conn) or die("Select database failed");
    $sql = Select code from jos_call where code = ".@$_REQUEST['nombre'].";";
    echo "my SQL is:".$sql;


    option C should read
    $sql = "Select code from jos_call where code = ".@$_REQUEST['nombre'].";";

    there is a missing opening quote for the string starting Select

    try that and see what is reported in the SQL, and make sure its valid SQL... ie the $_REQUEST['nombre'] is the value you expect.
    I'd also take out the @ sign in front of the $_REQUEST['nombre']
    I'd suggest you make certain the or die statement is on the same line.. there may be some weird precendence implicit in the or die construct
    however the fault is suggesesting its to do with the connection to the DB... invalid MYSWL resource usually means the connection or db is banjaxed. have you got any scripts to work yet which interact with the MySQL db.. if so try copying and pasting the same connection code
    Last edited by healdem; 12-08-08 at 11:37.
    I'd rather be riding on the Tiger 800 or the Norton

  10. #10
    Join Date
    Dec 2008
    Posts
    30

    resolved

    Hello
    Resolved , the are one error in the script in this line must be the same
    variabel .Thank you very much for your time.I have taked this script from another page and the variabel was not the same.?????

    $query = mysql_query("Select * from jos_call where code = '".@$_REQUEST['nombre']."'",@$conn);

    if (mysql_num_rows($query)==0){


    but this work in the internet explorer 7 8 and firefox but not in the internet explorer 6 ????? this error at bottom of the page httml XMLHttpRequest undefined in index.php

    in the index.php

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>codigos</title>
    <script>
    function chk_usuario(){
    <!-- INICIO DE CODIGO -->
    var pos_url = 'comprueba.php';
    var nombre = document.getElementById('usuario').value;
    var req = new XMLHttpRequest();
    if (req) {
    req.onreadystatechange = function() {
    if (req.readyState == 4 && (req.status == 200 || req.status == 304)) {
    document.getElementById('resultado').innerHTML = req.responseText;
    }
    }
    req.open('GET', pos_url +'?nombre='+nombre,true);
    req.send(null);
    }
    }
    <!-- FIN DE CODIGO -->
    </script>
    </head>
    <body>
    <form id="form1" name="form1" method="post" action="">
    Comprobar Codigo<br />
    <input name="nombre" type="text" id="usuario" onKeyUp="chk_usuario();"/> <br /> <div id='resultado'></div><br />
    <input type="submit" name="Submit" value="Enviar" />
    </form>
    </body>
    </html>

  11. #11
    Join Date
    Dec 2008
    Posts
    30
    ohh this work in

    http://www.busca.se/ok/index.php
    i have only 1 code in db 324265

  12. #12
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote Originally Posted by maxbox

    but this work in the internet explorer 7 8 and firefox but not in the internet explorer 6 ????? this error at bottom of the page httml XMLHttpRequest undefined in index.php
    if there is a problem then its a problem in the HTML you are generating NOT the PHP.

    PHP runs on the server, the output of the PHP script targetted at browsers should be HTML or similar. HTML is rendered on the users browser. It is an never ending struggle developing for the web world. unless you application s important enough then its unlikely you can dictate to your users what browsers they should use. Mind you IE 6 is pretty old these days.
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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