php中批量修改数据库,php数据库修改语句

如何用php修改数据库中的数据

举例如下:

创新互联专业提供成都棕树电信机房服务,为用户提供五星数据中心、电信、双线接入解决方案,用户可自行在线购买成都棕树电信机房服务,并享受7*24小时金牌售后服务。

创建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怎么批量修改mysql数据

很easy的,你update ‘DBname’ ‘num’=‘?’ 就可以了。 DBname填数据库名,?填修改后的值。

PHP批量修改MYSQL的某个字段

很easy的,你update

‘DBname’

‘num’=‘?’

就可以了。

DBname填数据库名,?填修改后的值。

PHP 批量修改多条记录的Sql语句写法

另一个思路你试试:

html:

input type="text" name="A[]" /

input type="text" name="B[]" /

input type="hidden" name="ids[]" value="{$id}" /

php:

?php

$a = $_POST['A'];

$b = $_POST['B'];

$ids = $_POST['ids'];

foreach($a as $k = $v) {

$sql = "update abc set a='{$v}', b='{$b[$k]}' where id='{$ids[$k]}'";

mysql_query($sql);

}

php批量修改数据

function updatecols($table,$arr){

$sql = "update ".$table." set ";

$total = count($arr);

$i=1;

foreach($arr as $k=$v){

$sql .= $k."=".$v;

if($i$total){

$sql .= ",";

}

$i++;

}

return $sql;

}

echo updatecols("table1",array('col1'='123','col2'='345'));


网页题目:php中批量修改数据库,php数据库修改语句
文章地址:http://ybzwz.com/article/dsidsgi.html