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

  • Home
  • SEARCH
  • 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 8692105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:15:12+00:00 2026-06-13T00:15:12+00:00

Please I need help! I have been already 3 days with the same problem.

  • 0

Please I need help! I have been already 3 days with the same problem. I know that the query is not giving me a boolean true result. I dont even know what it is giving me. The problem it gives me is :

Warning: mysqli_prepare() expects parameter 2 to be string, object
given in C:\xampp\htdocs\caf\pages\log.php on line 48

I already tried converting the result into string, but I have seen that the problem is in the output given to me on this line:

$query_pages_result = mysqli_query($connection, $get_pages_query)  or die($myQuery."<br/><br/>".mysql_error());

So please someone help me to see if this line can give me the result I want, which is to see how many pages I have in the tables record. Thanks in advance!

<?php

session_start();

// GET PAGES RECORD FROM LOG TABLE: *********| Only the first time though:
if (isset($_SESSION['log']) != 'logging')
{
    //  Here, just creating a string:
    $pages_record = '';
    $insert_query = '';
    //      Get saved pages from the database:
    $connection = mysqli_connect($mach,$userna,$paso,$db) or die ("Error in log-page script: AB-1 - query: $insert_query." . mysqli_error());
    mysqli_select_db($connection,'cafeteria');

    //      Query string to pull all pages from table record:
    $get_pages_query = "select *  from `log-page` order by `log-id`";

    //      Query the database, and save result:
    $query_pages_result = mysqli_query($connection, $get_pages_query)  or die($myQuery."<br/><br/>".mysql_error());

    //      Check number of results returned:
    $num_of_results = '';

    if ($stmt = mysqli_prepare($connection, $query_pages_result)) {
    $num_of_results = mysqli_num_rows($stmt);

    if ($num_of_results > 0)
    {
        // Loop through the result array: Each time, one row, and then the next one ...
        for ($row = 0; $row < $num_of_results; $row++ )
        {
            // Getting one row:
            $get_row = mysqli_fetch_array($query_pages_result);
            // Extracting just the page name from the row:
            $one_page = substr($get_row["page"],strripos($get_row["page"],"/") + 1);
            // Adding this page name to the string created previously:
            if ($row == 0)
            {
                $pages_record .= $one_page;
            }
            else 
            {
                $pages_record .= ",".$one_page;
            }           
        }

        // Once all pages have been read and saved to the string
        // now we save it to the session:
        $_SESSION['logpages'] = $pages_record;
        $_SESSION['log'] = 'logging'; // This just tells us, we are logging pages to the database.
    }
    else 
    {
        // There are no pages in the table:
        $_SESSION['logpages'] = "";
        $_SESSION['log'] = 'logging'; // This just tells us, we are logging pages to the database.
    }
}

// Check if page is already in session list.
$pages_array = array();
if (strlen(isset($_SESSION['logpages'])) > 0 )
{
    // string variable that holds all pages separated by commas:
    $pages_string =  $_SESSION['logpages'];

    // creating an Array to hold all pages already logged in server:
    if (strstr($pages_string, ","))
    {
        $pages_array = explode(",", $pages_string);
    }
    else // just means there's only one page in the record
    {
        // so, we push it inside the array.
        array_push($pages_array, $pages_string);
    }

    // current page: [ We are extracting only the page, not the entire url, Exmp: login.php ]
    $current_page = substr($_SERVER['PHP_SELF'],strripos($_SERVER['PHP_SELF'],"/") + 1);

    // Check if current_page is in the array already:
    if (!in_array($current_page, $pages_array))
    {
        // IF is NOT in the array, then add it:
        array_push($pages_array, $current_page);

        // Add it to the Session variable too:
        $pages_string = implode(",", $pages_array);

        // Re-save it to SESSION:
        $_SESSION['logpages'] = $pages_string;

        // Now, add it to the database table "log-page""
        $connection = mysqli_connect($mach,$userna,$paso,$db) or die ("Unable to connect!");
        mysqli_select_db($connection,'cafeteria');

        // Query to insert page description into the table:
        // [ date - time - page - user ]
        $insert_query = "INSERT INTO `log-page` 
            (`date`, `time`, `page`, `user`) VALUES 
            ('".date("Y-m-d")."', '".date("H:i:s")."', '".$_SERVER['PHP_SELF']."', '".(isset($_SESSION['SESSION_UNAME']))."')"; 
            mysqli_select_db($connection,'cafeteria');

        // INSERTING INTO DATABASE TABLE:
        mysqli_query($connection, $insert_query) or die ("Error in log-page script: AB-2 - query: $insert_query." . mysqli_error($connection));
        // Done!
    }
    else 
    {
        // IF it IS in the list, just SKIP.
    }
}
else 
{
    // means, that there are absolutely no pages saved in the database, basically this is the first log:
    $_SESSION['logpages'] = substr($_SERVER['PHP_SELF'],strripos($_SERVER['PHP_SELF'],"/") + 1);    

    // Now, add it to the database table "log-page""
    $connection = mysqli_connect($mach,$userna,$paso,$db) or die ("Unable to connect!");
    mysqli_select_db($connection,'cafeteria');

    // Query to insert page description into the table:
    // [ date - time - page - user ]
    $insert_query = "INSERT INTO `log-page` 
        (`date`, `time`, `page`, `user`) VALUES 
        ('".date("Y-m-d")."', '".date("H:i:s")."', '".$_SERVER['PHP_SELF']."', '".(isset($_SESSION['SESSION_UNAME']))."')"; 
    mysqli_select_db($connection,'cafeteria');
    // INSERTING INTO DATABASE TABLE:
    mysqli_query($connection,$insert_query) or die ("Error in log-page script: AB-2 - query: $insert_query." . mysqli_error($connection));
    // Done!    
}

}?>
  • 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-13T00:15:13+00:00Added an answer on June 13, 2026 at 12:15 am

    The problem is with this line:

    if ($stmt = mysqli_prepare($connection, $query_pages_result)) {
    

    The second variable to mysqli_prepare needs to be the actual SQL query, not the result-object of executing the query with mysqli_query. You may have your logic backwards with this. You’re supposed to prepare the statement and then execute it. It looks like you’re executing it, and then trying to prepare it.

    Try to remove the $query_pages_result = mysqli_query(... line and change the rest to:

    if ($stmt = mysqli_prepare($connection, $get_pages_query)) {
        $stmt->execute();
    

    However, your query doesn’t have any binding parameters, so you may actually be able to just use mysqli_query and drop the mysqli_prepare in this situation – your preference really.

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

Sidebar

Related Questions

I need some help with a LINQ query in VB.Net, please. I have this
I desperately need help with a query that's been causing a lot of grief
Well, I know this has been already asked but i really need help, I've
Need some help, please. I have a line of horizontal thumbnails loaded as ONE
I need some help to get this right, please. I have created an iPad
I need to convert the function path::combine(path1, path2). Please help me if you have
Please i need someone to help convert this query entity(c#) form. select * from
[Update:] i know the problem... but need help to resolve this. The issue is
Hey guys sorry to ask but i need help with this query please I've
I know there have been many questions asking for help converting URLs to clickable

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.