Jump to content

Recommended Posts

My brain isn't working...

 

I am trying to get this Prepared Statement to pull Events from my database and display them, but get this error...

Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in /Users/user1/Documents/DEV/++htdocs/01_MyProject/events_9.php on line 30

 

 

Here is my code...

<?php
// Initialize a session.
session_start();

// Access Constants.
require_once('config/config.inc.php');

// Initialize variables.
$eventExists = FALSE;

// Connect to the database.
require_once(ROOT . 'private/mysqli_connect.php');


// ********************
// Build Event Query	*
// ********************

$id=1;

// Build query.
$q = 'SELECT id, name, location, date
				FROM show
				WHERE id=?';

// Prepare statement.
$stmt = mysqli_prepare($dbc, $q);

// Bind variable.
mysqli_stmt_bind_param($stmt, 'i', $id);

 

(The last line above is Line 30.)

 

 

 

Debbie

 

 

The mysqli_prepare function returns a boolean value, hence the error you are receiving;

Try

mysqli_stmt_bind_param($dbc, 'i', $id);

 

I've always had my code the way it was posted here.

 

(I just copied and pasted it from another part of my site that works.)

 

 

Debbie

 

 

Your prepare is failing due to an error of some kind.

 

A) You always need to use error checking/error reporting logic in your code so that you don't trigger follow-on errors when something fails.

 

B) If you echo mysqli_error($dbc) as part of your error reporting logic, it will tell you why the prepare statement failed.

 

Your prepare is failing due to an error of some kind.

 

A) You always need to use error checking/error reporting logic in your code so that you don't trigger follow-on errors when something fails.

 

B) If you echo mysqli_error($dbc) as part of your error reporting logic, it will tell you why the prepare statement failed.

 

You mean code that exits "gracefully" versus throwing an error like I got in NetBeans?

 

If so, how would you modify my code?

 

 

Debbie

 

Ignore my last statement(s), I totally misread your code and was giving information based on the mysqli_stmt_prepare function.

 

As for the problem at hand, you can wrap your column\table names in back-ticks

$q = 'SELECT `id`, `name`, `location`, `date`
				FROM `show`
				WHERE `id`=?';

 

Ignore my last statement(s), I totally misread your code and was giving information based on the mysqli_stmt_prepare function.

 

As for the problem at hand, you can wrap your column\table names in back-ticks

$q = 'SELECT `id`, `name`, `location`, `date`
				FROM `show`
				WHERE `id`=?';

 

Okay, but is using SHOW for a table or DATE for a field, evil??

 

 

Debbie

 

to be Frank SHOW is a MYSQL reserved word i would refrain from using it in a table name, as it would conflict with the MYSQL function name. not so sure about date.

 

hers is what i would do.

 

if($stmt = mysqli_prepare($dbc, $q)){
//execute query
$stmt->execute();
//bind parameter
$stmt->bind_param('i',$id);
}

 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.