Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我的代码中出现意外的T_其他错误,有人能看到吗?_Php_Mysql_Sql_Database - Fatal编程技术网

Php 我的代码中出现意外的T_其他错误,有人能看到吗?

Php 我的代码中出现意外的T_其他错误,有人能看到吗?,php,mysql,sql,database,Php,Mysql,Sql,Database,我找不到我的错误,能帮我一下吗?我正在尝试一个带有cookie的登录代码。提前谢谢你!我只是看不出我的错误。我希望有人能看到我错过的东西。错误在第47行的某个地方,但我知道这并不意味着它就在那里 <?php if(isset($_POST['sent']) && $_POST['sent'] == "yes") { foreach($_POST as $field => $value) { if(

我找不到我的错误,能帮我一下吗?我正在尝试一个带有cookie的登录代码。提前谢谢你!我只是看不出我的错误。我希望有人能看到我错过的东西。错误在第47行的某个地方,但我知道这并不意味着它就在那里

<?php
    if(isset($_POST['sent']) && $_POST['sent'] == "yes")
    {
        foreach($_POST as $field => $value)
        {
            if($value == "")
            {
                $blank_array[$field]= $value;
            }
            else
            {
                $good_data[$field]=strip_tags(trim($value));
            }
        }
    }

    if(@sizeof($blank_array) > 0)
    {
        $message = "<p style='color: red; margin-bottom: 0; font-weight: bold'> Error.</p>";
        extract($blank_array);
        extract($good_data);
        include("form_log.php");
        exit();
    }

    include("dbstuff.php");
    $cxn = mysqli_connect($host,$user,$password,$database) or die ("coulnt connect");
    $query = "SELECT first_name FROM customer WHERE user_name='$_POST[user_name]' AND       password=md5('$_POST[password]')";
    $result = mysqli_query($cxn,$query) or die ("couldnt query");
    $n_row = mysqli_num_rows($result);

    if($n_row < 1)
    {
        $message = "<p style='color: red; margin-bottom: 0; font-weight: bold'> Not found.     </p>";
        extract($_POST);
        include("form_log.php");
        exit();
    }
    else
    {
        $row=mysqli_fetch_assoc($result);
        setcookie("first_name",$row['first_name']);
        setcookie("auth","yes");
        header("Location: secret_page_cookie.php");
    }

    else
    {
        $user_name = "";
        $password = "";
        include("form_log.php");
    }
?>
如果($n_行<1){
$message=“

未找到。

”; 摘录(元);; 包括(“form_log.php”); 退出(); }否则{ $row=mysqli\u fetch\u assoc($result); setcookie(“first_name”,$row['first_name']); setcookie(“auth”、“yes”); 标题(“位置:secret_page_cookie.php”); }否则{ $user_name=“”; $password=“”; 包括(“form_log.php”); }
这里有两个
else
语句。您需要找出它所属的
语句或将其转换为
elseif
条件。

第47行:

else
{
$user_name = "";
$password = "";
include("form_log.php");
}

每个
只能有一个
else
,如果这是第二个
else
,最后还有两个else块,那么应该只有一个。您的代码很容易受到SQL注入攻击。不要通过串联来构造SQL字符串,而是使用参数化查询。

几乎所有开发人员都使用缩进来格式化代码是有原因的。我必须在这里提到SQL注入攻击和弱密码散列。此外,像您这样使用
include
,您很快就会后悔的,如果不打开form_log.php文件,就不可能真正读取代码中的内容。看起来像是一个理想的候选人转换成一个函数对我来说<代码>参数化了
当今最流行的单词。在东部,我可能已经纠正了之前的打字错误。。。iPad太聪明了……;)
else
{
$user_name = "";
$password = "";
include("form_log.php");
}