Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Simple SQL statement causing me hell!

Featured Replies

I have been playing around with this all morning and can't figure out for the life of me why this statement will not execute and keeps giving error:

 

An error occurred in script 'C:\wamp\www\budgetr\setup\setup_part_1.php' on line 215:

mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given

 

// Set vars manually for testing
$current_balance = 500.00;
$weeks_in_avg_term = 11;

// Compile query
$query = "INSERT INTO users (current_balance, weeks_in_avg_term) VALUES (?,?) WHERE id=?"; 

// Prepare the statement.
$result = mysqli_prepare($dbc, $query);

// Bind the variables as parameters.
mysqli_stmt_bind_param($result, 'dii', $current_balance, $weeks_in_avg_term, $uid);

// Execute prepared query.
mysqli_stmt_execute($result);

 

It's driving me mad!!! Usually I have an extra comma or typo in the query but I can't spot anything this time!!!!!!

 

Thanks!!!!

Pretty obviously, the $result is FALSE because the mysqli_prepare has somehow failed... so that's where you need to be looking. The query looks OK by inspection, which suggests there is some problem communicating with the server. Have you checked your connection? Alternatively, have you tried running the query directly on the server to ensure it definitely works as you expect? I usually try all my queries on the server first, then put them in code to help me debug as I go.

 

How about getting the error message itself with mysqli_error($dbc) and/or mysqli_connect_error()?

  • Author
Pretty obviously, the $result is FALSE because the mysqli_prepare has somehow failed... so that's where you need to be looking. The query looks OK by inspection, which suggests there is some problem communicating with the server. Have you checked your connection? Alternatively, have you tried running the query directly on the server to ensure it definitely works as you expect? I usually try all my queries on the server first, then put them in code to help me debug as I go.

 

How about getting the error message itself with mysqli_error($dbc) and/or mysqli_connect_error()?

 

Thankyou. I put the query into phpmyadmin directly and it didnt work. So manually did the operation and generated the php code from within phpmyadmin.

 

Didn't think of debugging like that. Thanks again.

quick glance (and not familiar with mysqli) but try

 

// Compile query
$query = "INSERT INTO users (current_balance, weeks_in_avg_term) VALUES ('?','?') WHERE id='?'";

I must be very slow today (blame it on my cold)!! Of course, a WHERE clause isn't permitted for an INSERT... in fact, it doesn't even make sense. INSERT means "create a new record" while WHERE is used for either an UPDATE or SELECT on existing records. What is the reason for the WHERE id=? in the first place? You obviously need to re-think the purpose of the query---did you mean UPDATE?

 

And no, I don't think you'd want to use '?' as that is a literal question mark, and not a parameter AFAIK. You should stick with just a ? for parameter replacements.

 

Hope that helps now (kicking myself :D).

  • Author
I must be very slow today (blame it on my cold)!! Of course, a WHERE clause isn't permitted for an INSERT... in fact, it doesn't even make sense. INSERT means "create a new record" while WHERE is used for either an UPDATE or SELECT on existing records. What is the reason for the WHERE id=? in the first place? You obviously need to re-think the purpose of the query---did you mean UPDATE?

 

And no, I don't think you'd want to use '?' as that is a literal question mark, and not a parameter AFAIK. You should stick with just a ? for parameter replacements.

 

Hope that helps now (kicking myself :D).

 

Thankyou again!

 

This newbie won't be adding WHERE clauses to INSERT again! :D

I must be very slow today (blame it on my cold)!! Of course, a WHERE clause isn't permitted for an INSERT... in fact, it doesn't even make sense. INSERT means "create a new record" while WHERE is used for either an UPDATE or SELECT on existing records. What is the reason for the WHERE id=? in the first place? You obviously need to re-think the purpose of the query---did you mean UPDATE?

 

And no, I don't think you'd want to use '?' as that is a literal question mark, and not a parameter AFAIK. You should stick with just a ? for parameter replacements.

 

Hope that helps now (kicking myself :D).

 

 

I wasn't being literal... Just showing values (unless ints) should be inside ' ' , glad you spotted the where clause... I missed that well and truely

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.