Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Aug 2008
    Posts
    29
    Thanks
    4
    Thanked 1 Time in 1 Post

    A few mysql errors I need help with

    Hi all,

    I am getting these errors on my script and can't seem to find a solution.

    Code:
    Warning: mysql_numrows() expects parameter 1 to be resource, string given in C:\wamp\www\mysite\lib\mysql.lib on line 23
    
    Warning: mysql_fetch_array() expects parameter 1 to be resource, string given in C:\wamp\www\mysite\lib\mysql.lib on line 29
    Here is the php code:

    PHP Code:
     function c(){
          global 
    $db_host$db_login$db_pswd;
          
    $db "mysql_connect($db_host,$db_login,$db_pswd)";
          return 
    $db;
      }

     function 
    q($q_str){
        global 
    $db_name;
        
    $r "mysql_query($db_name,$q_str)";
        return 
    $r;
     }

     function 
    d($db){
    //    mysql_close($db);
     
    }
     
     function 
    e($r)
     {
      if(
    mysql_numrows($r))
       return 
    0;
      else return 
    1;
     }
     
     function 
    f($r){
      return 
    mysql_fetch_array ($r);
     }
     
     function 
    nr($r){
      return 
    mysql_num_rows($r);
     } 
    The first error is on line 23 which is this code:

    Code:
     function e($r)
     {
      if(mysql_numrows($r))
       return 0;
      else return 1;
     }
    The second error is on line 29 which is this code:

    Code:
     function f($r){
      return mysql_fetch_array ($r);
     }
    Errors are highlighted in red.

    Thanks for any help.

  • #2
    New Coder
    Join Date
    Mar 2009
    Posts
    62
    Thanks
    19
    Thanked 1 Time in 1 Post
    I belive that you are trying to use strings:

    $db = "mysql_connect($db_host,$db_login,$db_pswd)";
    $r = "mysql_query($db_name,$q_str)";

    Those above are strings, ie $hello="Hello World";


    $db = mysql_connect($db_host,$db_login,$db_pswd);
    $r = mysql_query($db_name,$q_str);

    Remove quotes and you will get "resources".
    Thats what I came up with first glance of the code.

  • #3
    Regular Coder
    Join Date
    Dec 2006
    Location
    In the wilderness
    Posts
    106
    Thanks
    9
    Thanked 5 Times in 5 Posts
    You are creating functions out of functions.. are more simpler way would be
    PHP Code:
    <?php
    $server 
    'server'// localhost or whatever
    $user 'dbusername';
    $password 'dbpassword';
    $db 'database';

    $conn mysql_connect($server$user$password) or die("Cannot connect to server ".mysql_error());
    mysql_select_db($db$conn) or die("Cannot find database " mysql_error());

    $query "SELECT column FROM table";
    $result mysql_query($query$conn) or die("Error in query: ".mysql_error());
    $rows mysql_num_rows($result);
    $row mysql_fetch_assoc($result); // or $row = mysql_fetch_array($result)
    Last edited by karlosio; 10-23-2009 at 04:34 PM.
    "The advantage of computers is that they do exactly what you tell them to do. The disadvantage of computers, on the other hand, is that they do exactly what you tell them to do."

    Excellent resource for learning PHP here

  • #4
    New Coder
    Join Date
    Aug 2008
    Posts
    29
    Thanks
    4
    Thanked 1 Time in 1 Post
    Thanks guys will give it a try. Sorry for the late reply have had internet malfunctions.


  •  

    Posting Permissions

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