سلام لطفا مثالی برای کار با UPDATE یا DELETE با bind بزنید
سلام،
مثالی برای UPDATE با mysqli:
$mysqli = new mysqli("localhost", "root", "", "mydb");
// Check if the connection was successful
if ($mysqli->connect_errno) {
die("Connection failed: " . $mysqli->connect_error);
}
// Prepare an update statement$stmt = $mysqli->prepare("UPDATE users SET name = ?, email = ? WHERE id = ?");
// Bind the values$stmt->bind_param("sss", $name, $email, $id);
// Execute the statement$stmt->execute();
// Check if the statement was successfulif ($stmt->affected_rows > 0) {
echo"The record was updated successfully";
} else {
echo"The record was not updated";
}
مثالی برای DELETE:
// Prepare a delete statement$stmt = $mysqli->prepare("DELETE FROM users WHERE id = ?");
// Bind the value$stmt->bind_param("s", $id);
// Execute the statement$stmt->execute();
// Check if the statement was successfulif ($stmt->affected_rows > 0) {
echo"The record was deleted successfully";
} else {
echo"The record was not deleted";
}