php表单提交 - 检查未被识别

时间:2011-09-26 19:28:49

标签: php forms submission

我基本上从表单中接收了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 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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

答案 2 :(得分:0)

您在上面的行中将$ email设置为是或否。

答案 3 :(得分:0)

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