用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查询修改数据库名称
URL分享:http://azwzsj.com/article/doeggsg.html