php 表单提交检查不被识别

发布于 2024-12-06 18:04:08 字数 1866 浏览 0 评论 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";
}



?>

I basically took in 3 pieces of data from a form, and before processing them, I just wanted to make sure that all fields were filled in. So the focus of this is the second to last IF statement, checking if the different variables are empty. It seems to only be working for the first variable and I can't figure out how to make it apply to all of them.

<?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";
}



?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

街角卖回忆 2024-12-13 18:04:08

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

Make sure you clean your REQUEST variables before you put them in a MySQL query.

脱离于你 2024-12-13 18:04:08

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

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

迷爱 2024-12-13 18:04:08

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

You're setting $email to yes or no in the line just above.

画骨成沙 2024-12-13 18:04:08

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

In your if statement you are using the shortcut OR operator.... As soon as a single statement evaluates to true, the entire statement evaluates to true and there is no need to continue processing further.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文