The call seems to have been successful...but I really don’t know what the problem is with this notice
Modified as follows...function update($link, $data, $table, $where = null) {
<code>foreach ( $data as $key => $val ) { $set .= "{$key}='{$val}',"; } $set = trim ( $set, ',' ); $where = $where == null ? '' : ' WHERE ' . $where; $query = "UPDATE {$table} SET {$set} {$where}"; $res = mysqli_query ( $link, $query ); if ($res) { return mysqli_affected_rows ( $link ); } else { return false; }</code>
}
·······
I have also defined this set... There will still be problems = =
The call seems to have been successful...but I really don’t know what the problem is with this notice
Modified as follows...function update($link, $data, $table, $where = null) {
<code>foreach ( $data as $key => $val ) { $set .= "{$key}='{$val}',"; } $set = trim ( $set, ',' ); $where = $where == null ? '' : ' WHERE ' . $where; $query = "UPDATE {$table} SET {$set} {$where}"; $res = mysqli_query ( $link, $query ); if ($res) { return mysqli_affected_rows ( $link ); } else { return false; }</code>
}
·······
I have also defined this set... There will still be problems = =
You did not define the set variable in the function scope. The reason for reporting the notice is that this is not a fatal error. It just reminds you that using undefined variables may bring adverse consequences.
After reading your revised question, set is still not defined. To be defined before using it. .= is equivalent to using it, and it must be within the function scope, not the foreach scope.
The $set variable is not defined and needs to be defined first above foreach:
<code>$set = '';</code>
The number of rows displayed in general error reports, you can find the problem from the row above the row number
First define a variable $set
Undefined variableUndefined variable
$set must be defined first. If it is not defined, use ‘.=’ directly. This is wrong usage
Use error_reporting(0)
or modify error_reporting = E_ALL & ~E_NOTICE in php.ini
Variable initialization $set = '';foreach($data as $k=>$v){$set.="{$k}={$v},";}
Define $set = '';
before foreach