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 407341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:35:06+00:00 2026-05-12T17:35:06+00:00

Okay I’m new to php and mysql I tried to build a web page

  • 0

Okay I’m new to php and mysql I tried to build a web page hit counter but my page counter dosen’t update correctly and it gets the following warnings listed below.

Warning: mysqli_query() expects at least 2 parameters, 1 given in
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in

Here is the php code below.

<?php

$page = $_SERVER['SCRIPT_FILENAME']; 

// Query member data from the database and ready it for display
$mysqli = new mysqli("localhost", "root", "", "sitename");
$dbc = mysqli_query($mysqli,"SELECT id page FROM mysql_counter_logs WHERE page = '$page'");

if (mysqli_num_rows($dbc) == 0) {
    $mysqli = new mysqli("localhost", "root", "", "sitename");
    $dbc = mysqli_query($mysqli,"INSERT INTO mysql_counter_logs (page) VALUES ('$page')");
    mysqli_query($dbc);
} elseif (mysqli_num_rows($dbc) == 1) {
    $mysqli = new mysqli("localhost", "root", "", "sitename");
    $dbc = mysqli_query($mysqli,"UPDATE mysql_counter_logs SET hits = hits + 1 WHERE page = '$page'");
    mysqli_query($dbc);
}

//Retreives the current count
$count = mysqli_fetch_row(mysqli_query($mysqli,"SELECT hits FROM mysql_counter_logs"));

if (!$dbc) {
    // There was an error...do something about it here...
    print mysqli_error();
} 


//Displays the count on your site
print "$count[0]";

?>
  • 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-05-12T17:35:06+00:00Added an answer on May 12, 2026 at 5:35 pm

    An extract of your code :

    $mysqli = new mysqli("localhost", "root", "", "sitename");
    $dbc = mysqli_query($mysqli,"INSERT INTO mysql_counter_logs (page) VALUES ('$page')");
    mysqli_query($dbc);
    

    First of all, according to the manual of mysqli_query, when used as a function :

    mixed mysqli_query  ( mysqli $link  , string $query  [, int $resultmode  ] )
    

    Which means you have to pass your $mysqli variable as first parameter, and your query as a second parameter.

    What I don’t get is why you are using mysqli_query this way on the third line I copy-pasted, while you are using it correctly in the other parts of your code ?

    Are you sure you mean to use that function, here ?

    Also, knowing on which lines you are getting those error messages might help 😉

    Check you don’t do anything else “wrong” there — like ” mysqli_query() expects at least 2 parameters, 1 given “

    Thinking about it : mysqli_query will return boolean false if there is an error.

    In that case, you should not call mysqli_num_rows on the return value of mysqli_query, as it’s not a valid mysqli_result — hence the second error message.

    You are checking for $dbc at the end of your script, but it might be interesting to check it too a biit sooner — actually, after each call to mysql_query, I’d say.

    Also, as a sidenote : you probably don’t need to instance the mysqli class that many times : just instanciate it once, and then use the $mysqli variable for there rest of your script.

    Just for security, and to avoid any trouble, you might also want to use mysqli_real_escape_string on the $page variable, before injecting it into the queries.

    Oh, and, btw : you might be interested by the INSERT … ON DUPLICATE KEY UPDATE Syntax that MySQL allows to use 😉

    (Well, that is if page is the primary key of your table, at least…)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, so I have my post.php page. If you are not logged in, you'll
Okay so im working on this php image upload system but for some reason
Okay this question is very simple: I have a facebook page, and a website.
Okay, I feel a bit foolish for having to ask this but I guess
Okay - I have a dilemma. So far my script converts page titles into
Okay, this is probably a very basic question; but, I'm just getting back in
Okay, so the answer to my question might not be the problem but here's
Okay, I've looked all over the internet for a good solution to get PHP
Okay, I've seen but haven't programmed in C# before. You can assume I'm competent
Okay, so this probably sounds terribly nefarious, but I need such capabilities for my

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.