简体   繁体   中英

MySQLI + PHP Update/Select with bind_param posting but not echoing

I have been hacking away at this all day with only a successful 'UPDATE' to show for it. I am new to using MySQLI and seem to be encountering several issues with the script.

A volunteer uses an html form to input their email address, which is already in the database. Then the database reveals their schedule information and updates the 'confirmed' column from (default) 'NO' to 'YES'.

The update is showing as confirmed "YES" in the database, however the output isn't echoing on the page itself.

Here's the PHP: http://pastebin.com/KSPGuuae

Errors: UPDATE FAILED: () object(mysqli_stmt)#2 (0) { } 
        select FAILED: () object(mysqli_stmt)#3 (0) { }
Fatal error: Call to undefined method mysqli_stmt::get_result() in
/home/content/79/6007279/html/summerfest/display.php on line 119: 

119:  $result = $stmt->get_result();

You forgot to run $stmt->execute() before trying to fetch the result.

Also, get_result() was only introduced in PHP 5.3

For prior PHP versions you should use this query:

SELECT agreeName, position, shift_times, confirmed FROM volConfirm ... etc

Then inside PHP:

// bind result columns
$stmt->bind_result($agreeName, $position, $shift_times, $confirmed);
while ($stmt->fetch()) {
    // use $agreeName, $position, etc.
}

I prefer the way PDO works, though with PHP 5.3 at least mysqli is more workable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM