0
session_start();
include 'assets/config.php';

if(isset($_POST['username'])){

    $queryIsUsername = ("SELECT count(user) FROM users WHERE user = '$_POST['username']'"); //Error
    $actionQueryIsUsername = mysql_query($queryIsUsername);
    while($rowIsUsername = mysql_fetch_array($actionQueryIsUsername)) {
        $isUsername[] = $rowIsUsername['COUNT(user)'];
    }

    if($isUsername[0]="0"){

        header("Location: login.php?error=e1");
    }

    else{
//do stuff
}

我不确定出了什么问题,这是我的错误。我删除了 if 语句,错误消失了。

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /Applications/XAMPP/xamppfiles/htdocs/craftlist/index.php on line 7
4

3 回答 3

3

将其更改为

$queryIsUsername = ("SELECT count(user) FROM users WHERE user = '".$_POST['username']."'");

但这不是 SQL 注入安全的!

于 2013-05-08T23:45:12.140 回答
1

插入数组变量时,不应在键名周围加上引号。

我个人更喜欢串联:

"....".mysql_real_escape_string($_POST['username'])."...";

这是可能的语法中最容易阅读的。

于 2013-05-08T23:45:26.107 回答
0
$queryIsUsername = ("SELECT count(user) FROM users WHERE user = '$_POST['username']'"); //Error

应该

$queryIsUsername = ("SELECT count(user) FROM users WHERE user = '".$_POST['username']."'"); //Error

另一方面,您可能想查看 mysqli 或 PDO_MYSQL,因为 php mysql 扩展已被弃用。请参阅http://www.php.net/manual/en/intro.mysql.php

于 2013-05-08T23:45:51.877 回答