Home > Backend Development > PHP Problem > How to modify mysql data in php

How to modify mysql data in php

藏色散人
Release: 2023-03-07 21:00:02
Original
4074 people have browsed it

php method to modify mysql data: first obtain the user number through GET to query user information; then create an update.php file to modify user information; finally return the number of rows in the previous record through "mysql_affected_rows".

How to modify mysql data in php

The operating environment of this tutorial: Windows 7 system, PHP version 5.6. This method is suitable for all brands of computers.

Recommended: "PHP Video Tutorial"

PHP MYSQL Modify and Delete Data

Create userinfo_update.php for query User information, display the information first, then modify:

First obtain the user number through GET to query the user information:

 $sql = "select * from user_info where user_id='".$_GET['userId']."'";
 $result = mysql_query($sql,$con);
 if($row = mysql_fetch_array($result)){
}
Copy after login

How to modify mysql data in php

Page effect:

How to modify mysql data in php

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";
Copy after login

How to modify mysql data in php

Running results

How to modify mysql data in php

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);
Copy after login

How to modify mysql data in php

## Running results:

How to modify mysql data in php

successfully deleted

How to modify mysql data in php

The above is the detailed content of How to modify mysql data in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template