php查询并修改数据 php怎么实现修改数据功能
PHP网站数据库查询并修改
$sql = "SELECT meso FROM char DESC LIMIT 1";
网站建设哪家好,找创新互联公司!专注于网页设计、网站建设、微信开发、小程序定制开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了桥西免费建站欢迎大家使用!
$return = mysql_result(mysql_query($sql), 0);
$return = $return 220000 ? 200000 : $return;
//如果要直接修改数据请加上下边这句查询
mysql_query(UPDATE char SET meso = '200000' DESC LIMIT 1);
如何用PHP代码实现MySQL数据库的增删改查
?php
$con = mysql_connect("localhost:3306","root","");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
$result = mysql_query("SELECT * FROM user");
echo "table border='1'
tr
thUsername/th
thPassword/th
/tr";
while($row = mysql_fetch_array($result)) {
echo "tr";
echo "td" . $row['username'] . "/td";
echo "td" . $row['password'] . "/td";
echo "/tr";
}
echo "/table";
mysql_close($con);
?
从服务器中获取用户所有信息(SQL SELECT语句)并以表格形式出现
?php
$con = mysql_connect("localhost","root","");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
mysql_query("DELETE FROM user WHERE username = '$_POST[username]'");
mysql_close($con);
?
删除该用户所有信息delete.php
?php
$con = mysql_connect("localhost:3306","root","");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
$sql = "INSERT INTO user (username,password)
VALUES
('$_POST[username]','$_POST[password]')";
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
?
注册一个新用户insert.php
?php
$con = mysql_connect("localhost","root","");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
mysql_query("UPDATE user SET password = '$_POST[password]' WHERE username = '$_POST[username]'");
mysql_close($con);
?
修改一个用户密码update.php
html
head
titleFORM/title
/head
body
br /
h1Insert:/h1
form action="insert.php" method="post"
username:input type="name" name="username"/
br /
password:input type="password" name="password"/
input type="submit" value="submit"/
/form
br /hr /br /
h1Delete/h1
form action="delete.php" method="post"
username:input type="name" name="username" /
br /
Are you sure?input type="submit" value="sure" /
/form
br /hr /br /
h1Update/h1
form action="update.php" method="post"
username:input type="name" name="username"/
br /
You want to change your password into:input type="password" name="password"/
input type="submit" value="submit"/
/form
br /hr /br /
/body
/html
以上三个功能的提交源Operate.html
如何用php修改数据库中的数据
举例如下:
创建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($mark0){
echo "删除成功";
}else{
echo "删除失败";
}
mysql_close($con);
运行结果:
文章名称:php查询并修改数据 php怎么实现修改数据功能
网站链接:http://ybzwz.com/article/ddohocc.html