Results 1 to 3 of 3

Thread: MySQL and PHP trouble

  1. #1
    Join Date
    Mar 2008
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default MySQL and PHP trouble

    I keep getting this error message on numberous pages on my site Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/moneybux/public_html/index.php on line (number of line on page).. and the culprit is the third line. I don't want to delete it yet. Does anyone have any ideas of what to do and how?

    <?
    $sql = "SELECT * FROM tb_config WHERE item='click' and howmany='1'";
    $result = mysql_query($sql);
    $row = mysql_fetch_array($result);
    ?>

  2. #2
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Posting in the PHP forum will probably get you better results.

  3. #3
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    It seems that you might be using incorrect table name or field names in your query. Make sure that the there is table contains fields named item and howmany. I've reproduced this error in my local PC when I mentioned the table names or field names incorrectly in my SQL query.

    You can have a look at the code I've used

    PHP Code:
    <?php
    class database
    {
        private 
    $db_handle;
        private 
    $user_name;
        private 
    $password;
        private 
    $data_base;
        private 
    $host_name;
        private 
    $sql;
        private 
    $results;

        function 
    __construct($host="localhost",$user,$passwd)
        {
            
    $this->db_handle mysql_connect($host,$user,$passwd);
        }

        function 
    dbSelect($db)
        {
            
    $this->data_base $db;
            if(!
    mysql_select_db($this->data_base$this->db_handle))
            {
                
    error_log(mysql_error(), 3"/phplog.err");
                die(
    "Error connecting to Database");
            }
        }
        
        function 
    executeSql($sql_stmt)
        {
            
    $this->sql $sql_stmt;
            
    $this->result mysql_query($this->sql);
        }
        function 
    returnResults()
        {
            return 
    $this->result;
        }
    }

    $user "root";
    $passwd "";
    $db "testdb"
    $sql "SELECT * FROM users WHERE screenname = 'codeexploiter' AND password = '12345'";
    $dbObject = new database($host,$user,$passwd);
    $dbObject->dbSelect($db);
    $dbObject->executeSql($sql);
    $res $dbObject->returnResults();
    while(
    $record mysql_fetch_array($res))
    {
        echo 
    "Screen Name: " $record["ScreenName"] ." Password : " $record["Password"] ."<br/>";
    }
    ?>

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
  •