PHP ?? ?? ????: ??? ?? ?? ? ?? ??
?????? ?? ?? ???
?? ??????? ???? ??? ??? ????, ????, ?????? ?? ?? ??? ?????.
??? ???? ???, ?????? ??? ?? ??? ?????, ??? ?? ????? ?? ?????? ??? ??? ?? ????.
?? ?? ????? ??????? ???? ???. ?? ??? ??? ????, ??? ????, ?? ??? ???? ??? ?? ?? ??????. ??? ??? ??? ????? ?? ??? ?? ????.
?? ??? ??? ?? ??? ???? ??? ??? ? ????. ?? ??? ??? ????.
??? ?? ?? config.php? ?? ? ????. ??? ???? ?? ?? ??? ?????. ??? ??? ????.
<?php //數(shù)據(jù)庫服務(wù)器 define('DB_HOST', 'localhost'); //數(shù)據(jù)庫用戶名 define('DB_USER', 'root'); //數(shù)據(jù)庫密碼 define('DB_PWD', 'secret'); //庫名 define('DB_NAME', 'book'); //字符集 define('DB_CHARSET', 'utf8');
??? ?????. Connection.php ????? ??? ??????? ???? ?? ???? Connection.php ??? ???? ???. ??? ??? ????.
<?php include 'config.php'; $conn = mysqli_connect(DB_HOST, DB_USER, DB_PWD, DB_NAME); if (mysqli_errno($conn)) { mysqli_error($conn); exit; } mysqli_set_charset($conn, DB_CHARSET);
?? ? ??? Connection.php ??? ?? ???? ?????? ??? ??? ? ????.
include 'connection.php';
?? ??? ??? ?, ??? ??
???? ????? ???? ????? ???? ??? ?? ?? ???? ?????.
get? ?? ????? ???? ? ?? ?? ID? delete.php ??? ???.
??? ?? ? ???? ?? ID? POST? ?? delete.php ???? ?????.
- ? ? ? ?? ?? ???? ??? ?? ???? ?????.
???
??? SQL?
?? MySQL ??? ??? ? in ?? ?? ??? ? ??? ??????.
????? ????? in ?? ?? ???? ??? ?? ? ????.
join ??? ?? ?? ??? ??? id? 3, 4, 5? ???? ?????. ?? ?? ??? SQL ?? ??? ?? ???
if (is_array($_POST['id'])) { $id = join(',', $_POST['id']); } elseif (is_numeric($_GET['id'])) { $id = (int) $_GET['id']; } else { echo '數(shù)據(jù)不合法'; exit; }
?? ?? ?? ?? ??? ??? ??? ????.
delete from user where id in(3,4,5,6,8);
??? ???? ?? ?? ? ?? ?? ?? ??? ????.
delete from user where id in(3)
?? ?? ?? ??? ??? ????.
$sql = "delete from user where id in($id)";