如果我不是我的网页上的管理员没有真正的错误但它跳过if,则无法更新帐户

时间:2014-08-26 03:30:59

标签: php sql

由于某种原因,如果用户登录并且他不是管理员,则代码将在查询之前和echo $ admin之后跳过执行if语句;而我似乎无法弄清楚为什么。谁能帮我解决这个问题? 当我以管理员身份登录时,它完全没有任何问题。 admin作为1存储在数据库中,普通用户存储为0

这是我的代码:

<?php
session_start();
//server gegevens
$server     = "localhost";
$user_sql   = "root";
$wachtwoord = "";

//maakt verbinding met de database                                         geeft een foutmelding als het verbinden niet is gelukt
$connect = mysql_connect($server, $user_sql, $wachtwoord) or die("couldn't connect to server please try again later");

//selectreert de database
mysql_select_db("camping") or die("DB not found");

$Admin      = "";
$Knummer    = "";
$voornaam   = "";
$achternaam = "";
$Tussen     = "";
$username   = "";
$email      = "";
$Reg        = "";
$Straat     = "";
$Hnummer    = "";
$woonplaats = "";
$Postcode   = "";
$Tel        = "";
$Pw         = "";

if (isset($_POST['hidden']))
    $Knummer = strip_tags($_POST['hidden']);

if (isset($_POST['Voornaam']))
    $voornaam = strip_tags($_POST['Voornaam']);

if (isset($_POST['Achternaam']))
    $achternaam = strip_tags($_POST['Achternaam']);

if (isset($_POST['Username']))
    $username = strip_tags($_POST['Username']);

if (isset($_POST['Woonplaats']))
    $Woonplaats = strip_tags($_POST['Woonplaats']);

if (isset($_POST['email']))
    $email = strip_tags($_POST['email']);

if (isset($_POST['Tel']))
    $Tel = strip_tags($_POST['Tel']);

if (isset($_POST['Straat']))
    $Straat = strip_tags($_POST['Straat']);

if (isset($_POST['Hnummer']))
    $Hnummer = strip_tags($_POST['Hnummer']);

if (isset($_POST['Postcode']))
    $Postcode = strip_tags($_POST['Postcode']);

if (isset($_POST['admin'])) {
    $Admin = strip_tags($_POST['admin']);
    /*this if is because on the admin pannel you can type yes/no to update the admin status of an user and in the database the admin is logged as 1/0 */
    if ($Admin == "yes") {
        $Admin = 1;
    } else if ($Admin == "no") {
        $Admin = 0;
    } else {
        $Admin = $Admin;
    }
}

if (isset($_POST['tussen']))
    $tussen = strip_tags($_POST['tussen']);
else
    $tussen = " ";

echo $Admin;

if ($Knummer && $voornaam && $achternaam && $username && $Woonplaats && $Straat && $email && $Tel && $Hnummer && $Postcode && $Admin) {
    $query  = mysql_query("UPDATE users SET admin='$Admin', Username='$username' 
                                WHERE Klant_NR='$Knummer';");
    $query2 = mysql_query("UPDATE klant_gegevens SET Voornaam='$voornaam',Tussenvoegsel='$tussen',Achternaam='$achternaam',Straat='$Straat',H_nummer='$Hnummer',Postcode='$Postcode',Woonplaats='$Woonplaats',email='$email',Telefoon='$Tel'
                                WHERE Klant_NR='$Knummer';");
    header('Location: ' . $_SERVER['HTTP_REFERER']);
} else {
    echo " **error/skip message**";
}

?>

1 个答案:

答案 0 :(得分:0)

如果未设置“$ Admin”,则应收到“错误/跳过消息”。

设置错误报告级别,以便在有任何错误时收到PHP错误。

ini_set('display_errors', 1);
error_reporting(E_ALL);

您的代码格式不是很好,并且您有一个很长的if条件会导致错误的练习。最好将其设置为函数并循环输入以查找是否存在数据。一旦使用了良好的编码标准,就可以很容易地调试和诊断代码中的问题。

http://www.mediawiki.org/wiki/Manual:Coding_conventions/PHP