php mysql修改表单数据_php如何修改表单数据

php修改表单数据的方法:首先将code设为【type="hidden"】;然后修改页面默认值的选择,代码为【$db = new MySQLi("localhost","root","root","dbname")】。

c7f39d52aea1da46287865ccecfb6f76.png

php修改表单数据的方法:

1、code那一条在数据库里是主键,不能改,所以要把它设为type="hidden"。也可以用type="text" style="display:none"。也可用readonly属性,但不能用disable属性。(disable是使其不可用,虽然不能修改了,它也不向后面传递信息了。)

2、性别那里用三目运算符写比较简单。

3、修改页面默认值的选择。

4、$db = new MySQLi("localhost","root","root","dbname");在本页中只需写一次,后面插入的php代码中不需要再写。

第一个页面xiugai.php

无标题文档

修改数据

$code = $_GET["code"];

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

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

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

$arr = $result->fetch_row();

?>

姓名:
性别:

/>男

/>女

民族:

$snation = "select * from nation";

$rnation = $db->query($snation);

while($attr = $rnation->fetch_row())

{

//判断将要输出的民族是否和该人员的相同

if($arr[3]==$attr[0])

{

echo "{$attr[1]}";

}

else

{

echo "{$attr[1]}";

}

}

?>

生日:

第二个页面update.php<?php

$code = $_POST["code"];

$name = $_POST["name"];

$sex = $_POST["sex"];

$nation = $_POST["nation"];

$birthday = $_POST["birthday"];

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

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

if($db->query($sql))

{

header("location:main.php");

}

else

{

echo "修改失败!";

}想了解更多编程学习,敬请关注php培训栏目!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值