我正在添加一些服务器端表单验证(使用php),以防我的网站的一个用户关闭了javascript。在一种形式上,有10个可以更改的单独输入字段。有人可以告诉我哪个协议将使用较少的系统资源?在第一个中,我编写了一些mySQL变量来检查用户的当前设置,并将它们与发布的设置进行比较。如果所有10个发布的值都与当前值相同,请不要UPDATE数据库,否则更新数据库:
$login_id = $_SESSION['login_id'];
$sql1 = mysql_fetch_assoc(mysql_query("SELECT value1 FROM login WHERE login_id =
'$login_id'"));
$sql1a = $sql1['value1'];
// Eight More, then
$sql10 = mysql_fetch_assoc(mysql_query("SELECT value10 FROM login WHERE login_id =
'$login_id'"));
$sql10a = $sql10['value10'];
$Value1 = $_POST['Value1'];
// Eight More, then
$Value10 = $_POST['Value10'];
//Other validations then the following
if (($sql1a == $Value1)&&($sql2a == $Value2)&&.......($sql10a == $Value10)) {
echo "<script>
alert ('You haven't made any changes to your profile');
location = 'currentpage.php';
</script>";
}
else {
$sqlUpdate = mysql_query("UPDATE login SET value1 = '$Value1',....value10 = '$Value10'
WHERE login_id = '$login_id'");
echo "<script>
alert ('Your profile has been updated!');
location = 'currentpage.php';
</script>";
}//End php
OR只是使用用户发布的值(保留$ _POST变量)并避免使用比较行进行检查:[($ sql1a == $ Value1)&amp;&amp;($ sql2a == $ Value2)&amp;&amp; .......($ sql10a == $ Value10))并且直接进入
//Other validations then the following
$sqlUpdate = mysql_query("UPDATE login SET value1 = '$Value1',....value10 = '$Value10'
WHERE login_id = '$login_id'");
echo "<script>
alert ('Your profile has been updated!');
location = 'currentpage.php';
</script>";
感谢您的任何意见!
答案 0 :(得分:2)
如果我理解正确,那么您的问题是性能是否可以检查配置文件是否有修改。对我来说,在我检查了你的代码之后,这不仅仅是表现......
<script>
魔法。在结果PHP中,您始终可以显示类似于CSS样式的状态栏,以显示类似的信息。