mysql更新的代码_MySQL更新用户代码

我有一个表单提交后更新用户信息。当前设置只允许填写所有字段时提交表单。我需要为每个字段创建if语句,如果填充,更新,如果不是,不要。

我有下面列出的密码字段,描述了我想要为每个字段做什么,但我不确定是否可以在IF中列出多个变量,或者是否必须编写单独的IF语句并每次从数据库中选择

if($password != '') {

if($password != $password2) {

$error = '

Attention! Your passwords did not match.
';

}

if(strlen($password) < 5) {

$error = '

Attention! Your password must be at least 5 characters.
';

}

if($error == '') {

$sql = "UPDATE login_users

SET restricted = '$restrict',

company_name = '$company_name',

contact = '$contact',

email = '$email',

user_level = '$level',

password = MD5('$password')

WHERE user_id = '$id'";

$query = mysql_query($sql) or die("Fatal error: ".mysql_error());

echo "

Updated

";

echo "

User information (and password) updated for User ID $id ($company_name).
";

echo "

What to do now?


";

echo "« Back to Admin Panel | Go to the edit users page.";

}这里是我的一些代码

if(trim($id) == '1') {

$error = '

Attention! You cannot edit the main Administrator, use database.
';

} else if(trim($company_name) == '') {

$error = '

Attention! You must enter a company name.
';

} else if(trim($contact) == '') {

$error = '

Attention! You must enter a contact name.
';

} else if(!isEmail($email)) {

$error = '

Attention! You have entered an invalid e-mail address, try again.
';

} else if(trim($level) == '') {

$error = '

Attention! No user level has been selected.
';

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值