wright67uk Posted April 12, 2013 Share Posted April 12, 2013 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(); } Quote Link to comment https://forums.phpfreaks.com/topic/276881-mysqli-update-using-placeholders/ Share on other sites More sharing options...
davidannis Posted April 12, 2013 Share Posted April 12, 2013 (edited) My bad. I need to think about this. Edited April 12, 2013 by davidannis Quote Link to comment https://forums.phpfreaks.com/topic/276881-mysqli-update-using-placeholders/#findComment-1424454 Share on other sites More sharing options...
wright67uk Posted April 12, 2013 Author Share Posted April 12, 2013 Thankyou, i'm open to any suggestions, i'm new to the whole preparing statements and using placeholders! Quote Link to comment https://forums.phpfreaks.com/topic/276881-mysqli-update-using-placeholders/#findComment-1424456 Share on other sites More sharing options...
mac_gyver Posted April 12, 2013 Share Posted April 12, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/276881-mysqli-update-using-placeholders/#findComment-1424460 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.