php更新用户数据为空,php - 使用PHP更新数据库,而没有来自HTML表单的空值 - SO中文参考 - www.soinside.com...

我想更新我的SQL数据库,但表单中没有空值。那就是我所拥有的:if(isset($_POST['account_details_submit'])) {

$user_id = array_values($_SESSION['user_info'])[9];

$edited = date('d.m.Y h:i a');

if(isset($_POST['account_details_first_name']) and !empty($_POST['account_details_first_name'])) { $add .= " and `first_name` = '$_POST[account_details_first_name]'"; }

if(isset($_POST['account_details_last_name']) and !empty($_POST['account_details_last_name'])) { $add .= " and `last_name` = '$_POST[account_details_last_name]'"; }

if(isset($_POST['account_details_phone_number']) and !empty($_POST['account_details_phone_number'])) { $add .= " and `phone_number` = '$_POST[account_details_phone_number]'"; }

if(isset($_POST['account_details_address_1']) and !empty($_POST['account_details_address_1'])) { $add .= " and `address_1` = '$_POST[account_details_address_1]'"; }

if(isset($_POST['account_details_address_2']) and !empty($_POST['account_details_address_2'])) { $add .= " and `address_2` = '$_POST[account_details_address_2]'"; }

if(isset($_POST['account_details_city']) and !empty($_POST['account_details_city'])) { $add .= " and `city` = '$_POST[account_details_city]'"; }

if(isset($_POST['account_details_post_code']) and !empty($_POST['account_details_post_code'])) { $add .= " and `post_code` = '$_POST[account_details_post_code]'"; }

if(isset($_POST['account_details_country']) and !empty($_POST['account_details_country'])) { $add .= " and `country` = '$_POST[account_details_country]'"; }

$update = "UPDATE `users` SET `edited` = '$edited'".$add." WHERE `id` = '$user_id'";

if ($conn->query($update) === TRUE) {

echo "Record updated successfully";

} else {

echo "Error updating record: " . $conn->error;

}

}

消息为“记录已成功更新”,但只有一行正在更新的行称为“ [[已编辑”,并且该行始终更新为0我愿意以其他方式做到这一点。

P.S,我尝试使用数组值来执行此操作,但结果不是我想要的]]

我想更新我的SQL数据库,但表单中没有空值。这就是我得到的:if(isset($ _ POST ['account_details_submit'])){$ user_id = array_values($ _ SESSION ['user_info'])[9]; $ edited = ...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值