i have an update function that updates a specific row in the table. The sql query works in PHPmyadmin and I am always returned true on the function. However, the database is not updated. I looked over the code and nothing appears wrong. What could be the problem. primary_id is the primary id of the table and the only other column is fund_max.
function change_fund_max ($mysqli, $project_id, $fund_max) {
if ($stmt = $mysqli->prepare("UPDATE `project_fund_max` SET `fund_max` = ? WHERE
`project_id` = ?")){
$stmt->bind_param('ii', $project_id, $fund_max);
$return = $stmt->execute();
$stmt->close();
return $return;
} else {return false;}
}
Here is the use of the function.
$fund_max = 11.55;
$project_id = 1;
$row43 = change_fund_max ($mysqli, $project_id, $fund_max);
var_dump($row43);
Execute will only return
falseon a failure… like you messed up the SQL or something. What you really want to know is did the command actually update on the rows… checkmysqli_stmt_affected_rowsto see if more than zero rows where changed.Also your
project_idandfund_maxparameters are the wrong way around in yourbind😉Result:
Update: For sneaky “fund_max is a decimal” comment… if fund_max is a decimal you need to bind to a double otherwise you’re loosing anything right of the decimal place during the
bind_paramcommand (my code updated)