Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7970389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:23:30+00:00 2026-06-04T07:23:30+00:00

I am having a small problem with my PHP MySQL Select. The function is

  • 0

I am having a small problem with my PHP MySQL Select. The function is inside of a PHP class. Here is the error I get:

Warning: mysql_fetch_array() expects parameter 1 to be resource,
integer given in C:\xampp\htdocs\include\database.php on line 59
Warning: extract() expects parameter 1 to be array, null given in
C:\xampp\htdocs\include\database.php on line 59

The function just simply updates the database to show what browser and OS they visited the site with. The function is called from another file that is called by an AJAX call that uses POST to send the data about the OS and browser that was gathered from a Javascript file. It only fails if there is an entry of the IP address already in the database. If there is no IP Address entry in the database it succeeds in creating one.

Here is my code:

function addStat($browser, $os){
    $IE = 0; $Firefox = 0; $Safari = 0; $Opera = 0; $Chrome = 0; $otherb = 0;
    $Windows = 0; $Linux = 0; $Mac = 0; $Android = 0; $iOS = 0; $otheros = 0;
    $ql = 0; $totalVisits = 0;
    $ip = ip2long($_SERVER['REMOTE_ADDR']);
    $q1 = mysql_query("SELECT * FROM " . DB_STATS . " WHERE ip='$ip'", $this->connection);
    if (mysql_num_rows($q1)==0){
        $browser = mysql_real_escape_string($browser);
        $os = mysql_real_escape_string($os);
        switch($browser){
            case "Internet Explorer":
                $IE += 1;
            break;
            case "Firefox":
                $Firefox += 1;
            break;
            case "Safari":
                $Safari += 1;
            break;
            case "Opera":
                $Opera += 1;
            break;
            case "Chrome":
                $Chrome += 1;
            break;
            default:
                $otherb += 1;
            break;
        }
        switch($os){
            case "Windows":
                $Windows += 1;
            break;
            case "Mac OS X":
                $Mac += 1;
            break;
            case "Linux":
                $Linux += 1;
            break;
            case "Android":
                $Android += 1;
            break;
            case "iOS":
                $iOS += 1;
            break;
            default:
                $otheros += 1;
            break;
        }
        $q = $this->query("INSERT INTO " . DB_STATS . " VALUES (null, '$ip', '$Chrome', '$IE', '$Firefox', '$Opera', '$Safari', '$otherb', '$Windows', '$Mac', '$Linux', '$Android' , '$iOS' , '$otheros', 1)");
        if ($q == true){
           return(1);
        }
        else{
           return(0);
        }
    }
    else if (mysql_num_rows($q1)==1){
        extract(mysql_fetch_array($ql));
        switch($browser){
            case "Internet Explorer":
                $IE += 1;
            break;
            case "Firefox":
                $Firefox += 1;
            break;
            case "Safari":
                $Safari += 1;
            break;
            case "Opera":
                $Opera += 1;
            break;
            case "Chrome":
                $Chrome += 1;
            break;
            default:
                $otherb += 1;
            break;
        }
        switch($os){
            case "Windows":
                $Windows += 1;
            break;
            case "Mac OS X":
                $Mac += 1;
            break;
            case "Linux":
                $Linux += 1;
            break;
            case "Android":
                $Android += 1;
            break;
            case "iOS":
                $iOS += 1;
            break;
            default:
                $otheros += 1;
            break;
        }
        $totalVisits += 1;
        $q = $this->query("UPDATE " . DB_STATS . " set Chrome='$Chrome', IE='$IE', Firefox='$Firefox', Opera='$Opera', Safari='$Safari', otherb='$otherb', Windows='$Windows', Mac='$Mac', Linux='$Linux', Android='$Android' , iOS='$iOS' , otheros='$otheros', totalVisits='$totalVisits'");
        if ($q == true){
           return(1);
        }
        else{
           return(0);
        }
    }
    else{
        return(-1);
    }
}

I hope everything made sense and that someone will help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:23:31+00:00Added an answer on June 4, 2026 at 7:23 am

    I see it now — you used $ql (lower case L) when you intend to use $q1. Let this be a lesson against using very short variable names or very similar names.

    // $ql was initialized to 0
    $ql = 0; $totalVisits = 0;
    
    // $q1 holds the result resource
    extract(mysql_fetch_array($q1));
    

    It is not advisable to call extract() on the output of mysql_fetch_array() unless you also specify the second parameter MYSQL_ASSOC as the fetch type. By default it returns both numeric and associative indices for each column.

    extract(mysql_fetch_array($q1, MYSQL_ASSOC));
    // Or better
    extract(mysql_fetch_assoc($q1));
    

    In general, I would probably advise against using extract() in most any situation, since it results in numerous variables dumped into the global namespace, in particular when you have done SELECT * without being specific about which columns are selected. Better to access them via their array:

    $row = mysql_fetch_assoc($q1);
    echo $row['browser'];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a small issue here: <div id=navbar> <ul id=navtabs class=floatcontainer> <li <?php if
im having small problem within my file creator class . im a little bit
I'm having what seems to be a concurrency problem while using MySQL and PHP
i am having a small problem here. The table which dbml (LinqToSql designer) is
I'm having a small problem with replaceWith fadeIn and fadeOut functions: $('#form').fadeOut(300, function() {
i'm having a small problem here. I'm using a simple rule to redirect all
I'm currently having a small problem with the following regex in PHP: preg_match_all('/(.*)(XS|S|M|XL|XXL|L)(.*)/i', '00236XL00',
I am having a small problem here with an IF condition in an ajax
Im having a small problem with storage of special characters like quotes, double quotes
Im having a small problem with my code. I have been trying to read

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.