Php 无法在sql查询中使用if/else

Php 无法在sql查询中使用if/else,php,mysql,Php,Mysql,我无法执行此查询: $sl="update customers set activation_code='$reg' WHERE c_number='$users1' and password='$id'"; $result=mysql_query($sl); if (mysql_error()) { ?> <script type=text/javascript> window.alert("Error, You have not used o

我无法执行此查询:

$sl="update customers set activation_code='$reg' WHERE  c_number='$users1' and password='$id'";
$result=mysql_query($sl);
if (mysql_error()) {
    ?>
    <script type=text/javascript>
       window.alert("Error, You have not used our services before, so no details for you to visit and explore");
    </script>
    <?php
} else {
    echo $reg;
}
$sl=“更新客户设置激活”\u代码=“$reg”,其中c\u编号=“$users1”和密码=“$id”;
$result=mysql\u查询($sl);
if(mysql_error()){
?>
window.alert(“错误,您以前没有使用过我们的服务,因此没有可供您访问和探索的详细信息”);

你已经两次使用WHERE子句了

$sl="update customers set activation_code='$reg' WHERE  c_number='$users1' and password='$id'"

你的意思是:“更新客户集激活”\u code='$reg',其中c\u number='$users1'和password='$id'?请检查我编辑的问题…我已经完成了你所说的..但现在我的错误是:在all@MaryamButt:为此,您必须通过mysql\u query()检查$result变量返回;我也检查了,但没有结果……还是有问题sustains@MaryamButt:检查$result,如果为true,则更新行,否则不更新行。您还可以打印该查询并在mysql(phpmyadmin)中执行,并查找查询的错误。供将来参考(至少在开发时)最好显示实际的SQL错误消息,并在需要此类帮助时将其发布在此处。该消息会准确地告诉您SQL语句中的问题所在。同样,请停止使用MySQL扩展,因为它受到SQL注入的影响,现在在PHP中已被弃用;并学习使用准备好的语句使用MySQLi或PDO扩展。