Jump to content

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.

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.