本文主要是介绍PHP PDO MySql 编辑用户 useredit.php,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
<?php include "i_conn.php" ?>
<?php
$Opt = "";
if(!empty($_REQUEST["Opt"])){ //@$_REQUEST["Opt"] 加个@符号可以消除提示 isset()函数 一般用来检测变量是否设置 empty()函数 判断值为否为空 $Opt = $_REQUEST["Opt"];
}if(!is_numeric($Opt)){$Opt = 0;
}
if($Opt>1 || $Opt<0){$Opt = 0;
}$strUserName = "";
$strUserPwd = "";
$strRealName = "";
if($Opt==1){$UserID = $_REQUEST["UserID"];if(!is_numeric($UserID)){$UserID = 0;}if($UserID<=0){echo "参数错误!";exit();}$strSQL = "select * from Users where UserID=".$UserID;$rst = $pdo->query($strSQL);if($rstUser=$rst->fetch()){$strUserName = $rstUser["UserName"];$strUserPwd = $rstUser["UserPwd"];$strRealName = $rstUser["RealName"];}else{echo "参数错误!";exit();}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>编辑用户</title>
</head><body>
<h3>编辑用户</h3>
<form name="editform" action="" method="post">
<p>用户名: <input type="text" name="username" value="<?php echo $strUserName; ?>" /></p>
<p>密码: <input type="password" name="userpwd" value="<?php echo $strUserPwd; ?>" /></p>
<p>真实姓名:<input type="text" name="realname" value="<?php echo $strRealName; ?>" /></p>
<p><input type="submit" name="sub" value="提交" /></p>
</form>
<?php
if(@$_REQUEST["sub"]=="提交"){$UserName = trim($_REQUEST["username"]);$UserPwd = trim($_REQUEST["userpwd"]);$RealName = trim($_REQUEST["realname"]);if($Opt==0){$strSQL = "insert into Users(UserName,UserPwd,RealName) values('".$UserName."','".$UserPwd."','".$RealName."')";}else if($Opt==1){$strSQL = "update Users set UserName='".$UserName."',UserPwd='".$UserPwd."',RealName='".$RealName."' where UserID=".$UserID;}$pdo->exec($strSQL);echo "<script>alert('编辑成功!');window.location.href='index.php';</script>";
}
?>
</body>
</html>
这篇关于PHP PDO MySql 编辑用户 useredit.php的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!