推薦:《PHP視頻教程》
該方法適用于所有品牌電腦。
PHP MYSQL 修改刪除數據
創建userinfo_update.php,用于查詢用戶信息,先顯示信息,在修改:
先通過GET獲取用戶編號查詢用戶信息:
$sql = "select * from user_info where user_id='".$_GET['userId']."'"; $result = mysql_query($sql,$con); if($row = mysql_fetch_array($result)){ }
頁面效果:
創建update.php文件,用于修改用戶信息:
使用到了mysql_affected_rows() 函數返回前一次 MySQL 操作所影響的記錄行數。
//通過post獲取頁面提交數據信息 $userId = $_POST[userId]; $userName = $_POST[userName]; $userAge = $_POST[userAge]; $sql = "update user_info set user_name='".$userName."',user_age=".$userAge." where user_id='".$userId."'"; mysql_query($sql,$conn);//執行SQL $mark = mysql_affected_rows();//返回影響行數 $url = "userinf_select.php";
運行結果
創建delete.php文件,完成刪除用戶信息功能:
$userId = $_GET['userId']; include 'connection.php'; $sql = "delete from user_info where user_id='".$userId."'"; mysql_query($sql,$con); $mark = mysql_affected_rows();//返回影響行數 if($mark>0){ echo "刪除成功"; }else{ echo "刪除失敗"; } mysql_close($con);
運行結果:
刪除成功
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com