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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:01:31+00:00 2026-06-04T20:01:31+00:00

my goal here is to be able to get a variable (with php) and

  • 0

my goal here is to be able to get a variable (with php) and use it in a prepared statement (with mysqli), and then fetch_assoc. For some reason this code will not work (no errors). I’ve rtm and I haven’t found anything combining fetch_assoc with prepared statements, so I’m not sure if it’s even possible. Any help to get this working is appreciated, here’s my code currently.

$where = $_GET['section'];
            $mysqli = mysqli_connect("localhost", "root", "","test");

            if($stmt = mysqli_prepare($mysqli,"SELECT title, img, active, price FROM ? ORDER by ID limit 5 ")){
                mysqli_stmt_bind_param($stmt, 's', $where);
                mysqli_stmt_execute($mysqli);
                mysqli_stmt_fetch($mysqli);
                 while($row = mysqli_fetch_assoc($stmt)){
                    if($row['active']=="yes"){
                        echo 'the rest of my stuff goes here';
  • 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-04T20:01:32+00:00Added an answer on June 4, 2026 at 8:01 pm

    From the PHP website page for mysqli->prepare (with emphasis added to the most relevant part):

    Note:

    The markers are legal only in certain places in SQL statements. For
    example, they are allowed in the VALUES() list of an INSERT statement
    (to specify column values for a row), or in a comparison with a column
    in a WHERE clause to specify a comparison value.

    However, they are not allowed for identifiers (such as table or column
    names)
    , in the select list that names the columns to be returned by a
    SELECT statement), or to specify both operands of a binary operator
    such as the = equal sign. The latter restriction is necessary because
    it would be impossible to determine the parameter type. In general,
    parameters are legal only in Data Manipulation Language (DML)
    statements, and not in Data Definition Language (DDL) statements.

    Assuming you can get past that problem, your use of mysqli is a little confused. You correctly bind your parameters and execute, but you’ve mixed up two different ways of getting at your results. Either

    1. Use mysqli_stmt_get_result to fetch the result set and then use mysqli_fetch_assoc on that, or
    2. Bind your results with mysqli_stmt_bind_result, and then use mysqli_stmt_fetch to fetch the next set of results into your bound variables. (Usually you’d iterate over the results using something like while(mysqli_stmt_fetch($stmt)){ //do stuff here }
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My goal here is to open temp.php, explode by ### (line terminator), then by
The goal here is to take some list of coordinates, like [[1,2],[3,4],[7,1]] , then
I'm using PHP's simplexml_load_file to get some data from Flickr. My goal is to
I have some code here. I recently added this root_id parameter. The goal of
My goal here is to use multiple wordpress loops to style each post in
Here is my ultimate goal... to take this xml file.. <?xml version=1.0?> <Songs> <Song>
Here's my ultimate goal in all of this. I have a viewcontroller with a
Here is my goal: I would like to be able to report various metrics
The goal here is to be able to step into the WCF service code,
How can I write this jQuery more efficiently? The goal is to be able

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.