Jump to content

mysqli update using placeholders


wright67uk

Recommended Posts

The below updates records for the month of jan, feb, mar ect although I'm expecting only records that have the month of feb to be updated.  Is my update syntax wrong somhow?

 

Also how can I echo the update statement whilst using mysqli?

 

Many thanks for any help.

 

$id = ''; $name = 'the novice tipster'; $year = 2013; $month = 'feb';  $wins = 12;

if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());exit();}

if ($stmt = $mysqli->query("SELECT * FROM compare WHERE name = '$name' and month = '$month' and year = '$year' ")) {
    $row_cnt = $stmt->num_rows;
    printf("Result set has %d rows.\n", $row_cnt);	
    $stmt->close();}

if ($row_cnt > 0) {	
$stmt = $mysqli->prepare("UPDATE compare SET wins = ? WHERE name = ? AND month = ? AND year = ? "); 
$stmt->bind_param('isii', $wins, $name, $month, $year);
$stmt->execute();
$stmt->close();  }

 

Link to comment
https://forums.phpfreaks.com/topic/276881-mysqli-update-using-placeholders/
Share on other sites

you are binding the month as though it is an integer. it is apparently the month abbreviation, a string. the internal conversion of those mismatched data types is probably causing all the month values to be matched.

 

make sure you are treating data as the correct type.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.