0

我基本上是从一个表单中取了3条数据,在处理它们之前,我只是想确保所有的字段都被填写。所以这里的重点是倒数第二个IF语句,检查不同的变量是否为空. 它似乎只适用于第一个变量,我不知道如何使它适用于所有变量。

<?php



include ("account.php") ;
include ("connect.php") ;


$isdone = FALSE;
$un  =  $_REQUEST [ "un"] ; 
$pw   =  $_REQUEST [ "pw"] ;



$data = mysql_query("SELECT * FROM `auth` WHERE username = '$un'") or die(mysql_error());

$info = mysql_fetch_array($data);

$info['username']; 
$password = $info['pw'];

session_start();


if(trim($un) != '' && trim($pw) != '' && $password == $pw)
{

    $_SESSION['uze']=$un;


    include "problem.html";

}


elseif( !isset($_POST['submit1']) && $isdone == FALSE)
{
    echo "wrong password";
}



$selected =  $_REQUEST [ "type"] ; 


if($selected == 'afs')
{
    $typeinc = 'afs';
}
else if($selected == 'db')
{
    $typeinc = 'database';
}
else if($selected == 'cs')
{
    $typeinc = 'computer systems';
}
else if($selected == 'pw')
{
    $typeinc = 'password';
} 
else if($selected == 'hw')
{
    $typeinc = 'hardware';
}
else if($selected == 'other')
{
    $typeinc = 'other';
}

$text = $_REQUEST ["inc"];

$selected2 = $_REQUEST ["yesno"];

if($selected2 == 'yes')
{
    $email = 'yes';
}
else
{
    $email = 'no';
}



if(isset($_POST['submit1']))
{
    if(empty($typeinc) || empty($text) || empty($email))
    {
        print( '<a href="http://web.njit.edu/~swp5/assignment/auth.html">You have not filled in all fields, click to sign in and re-enter</a>' );
    }

}


else{
    mysql_query("INSERT INTO `swp5_proj`. `inci` (`type`, `date`, `time`, `reporter`, `desc`) VALUES ('$typeinc', CURDATE(), CURTIME(), '".$_SESSION['uze']."', '$text');") or die(mysql_error());

    mysql_query("DELETE FROM inci WHERE type = ' '");
$isdone = TRUE;

}

if(isset($_POST['submit1']) && $isdone == TRUE)
{
    echo "session over";
}



?>
4

4 回答 4

0

if((trim($un) !== '') && (trim($pw) !== '') && ($password == $pw))

于 2011-09-26T19:35:11.550 回答
0

确保在将 REQUEST 变量放入 MySQL 查询之前清理它们。

于 2011-09-26T19:35:13.367 回答
0

您在上面的行中将 $email 设置为 yes 或 no。

于 2011-09-26T19:35:43.163 回答
0

在您的 if 语句中,您使用的是快捷方式 OR 运算符...。只要单个语句的计算结果为真,整个语句的计算结果就为真,无需继续进一步处理。

于 2011-09-26T19:35:53.440 回答