April 14, 200917 yr 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!!!!
April 14, 200917 yr 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()?
April 14, 200917 yr 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.
April 14, 200917 yr quick glance (and not familiar with mysqli) but try // Compile query $query = "INSERT INTO users (current_balance, weeks_in_avg_term) VALUES ('?','?') WHERE id='?'";
April 14, 200917 yr 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 ).
April 14, 200917 yr 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 ). Thankyou again! This newbie won't be adding WHERE clauses to INSERT again!
April 15, 200917 yr 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 ). 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