Home > Article > Backend Development > How to modify data in database in php
php method to modify data in the database: first create "userinfo_update.php" to query user information; then obtain the user number through GET to query user information; finally create the "update.php" file for modification Just user information.
Recommended: "PHP Video Tutorial"
Create userinfo_update.php, used to query user information, display first Information, modifying:
First obtain the user number through GET to query user information:
$sql = "select * from user_info where user_id='".$_GET['userId']."'"; $result = mysql_query($sql,$con); if($row = mysql_fetch_array($result)){ }
Page effect:
Create the update.php file to modify user information:
The mysql_affected_rows() function is used to return the number of record rows affected by the previous MySQL operation.
//通过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";
Running results
Create delete.php file , Complete the function of deleting user information:
$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);
## Running results: successfully deleted
The above is the detailed content of How to modify data in database in php. For more information, please follow other related articles on the PHP Chinese website!