que..._mysq 修i该表中一条数据">
当前位置:   article > 正文

mysql根据i修改数据_MYSQLi数据访问修改数据

mysq 修i该表中一条数据

代号姓名性别民族生日操作

$db = new MySQLi("localhost","root","123456","crud");

$sql = "select info.code,info.name,sex,nation.name,birthday from info,nation where info.nation=nation.code";

$result = $db->query($sql);

if($result){

$arr = $result->fetch_all();

foreach($arr as $v){

$sex = $v[2]?"男":"女";

echo "

{$v[0]}{$v[1]}{$sex}{$v[3]}{$v[4]} 修改";

}

}

?>

4e3b0e3719c62822946d49856e44bdd8.png

第二个文件修改页

无标题文档

修改数据

//取出主键值

$code = $_GET["code"];

//读取该条数据

$db = new MySQLi("localhost","root","123456","crud");

$sql = "select * from info where code='{$code}'";

$result = $db->query($sql);

$arr1 = $result->fetch_row();

?>

代号:

姓名:

性别:

男 />

女 />

民族:

$sql = "select * from nation";

$result = $db->query($sql);

if($result){

$arr = $result->fetch_all();

foreach($arr as $v){

if($v[0]==$arr1[3]){

echo "{$v[1]}";

}else{

echo "{$v[1]}";

}

}

}

?>

生日:

d37e41b9c035a63ad22cee307a30eba1.png

三、执行页面

$code = $_POST["code"];

$name = $_POST["name"];

$sex = (int)$_POST["sex"];

$nation = $_POST["nation"];

$birthday = $_POST["birthday"];

$db = new MySQLi("localhost","root","123456","crud");

$sql = "update info set name='{$name}',sex={$sex},nation='{$nation}',birthday='{$birthday}' where code='{$code}'";

$result = $db->query($sql);

if($result){

header("location:main.php");

}else{

echo "修改失败!";

}

25b2ad85fe759104975f7e133ee81a24.png

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/592864
推荐阅读
相关标签
  

闽ICP备14008679号