0

我想创建一个表单并将表单的值与数据库匹配。我已经尝试过,但我失败了并且有一个奇怪的错误。CSRF 状态令牌与提供的不匹配。我是新手,需要一些帮助

   <?php
header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"');
include_once "fbmain.php";
include_once "mysqli.connect.php";
mysql_connect(".....") or die(mysql_error()) ;
mysql_select_db("jetstardatabase") or die(mysql_error()) ;

?>    
<html>
    <link type= "text/css" rel="stylesheet" href="starpickStyle.css">

    <head>
        <title>StarPick</title>

    </head>
    <body>
<?php
if (!isset($_POST["code"]))
{
?>

<form action="" method="post">

 <strong>Code: *</strong> <input type="text"  name = "code" >
 <input type="submit" name="submit" value="Submit">
    </form>
    <?php
}else
{
$code = $_POST["code"]; }
$sql = "SELECT bookingref FROM starpick WHERE obsolete = 0";
$result = $mysqli->query($sql);

while($row = $result->fetch_object())
{           
    if($row->bookingref == $code)
    {
        echo 'Found';
    }
    else
    {
        echo 'Try Again';
    }
}
?>
</body> 
</html>
4

1 回答 1

0

你接近它错了,你需要让数据库进行匹配,而不是获取所有行并在 php.ini 中进行匹配。

就像是:

$sql = "SELECT bookingref FROM starpick WHERE obsolete = 0 AND bookingref='" . mysql_real_escape_string($_POST["code"]) . "'";    // better use a prepared statement by the way but you'll have to check the manual for mysqli

然后检查是否找到一行。

我自己使用 PDO,但这里是mysqli 准备语句的手册

于 2012-01-18T15:05:57.150 回答