Php的准备声明

时间:2012-10-11 19:00:54

标签: php login prepared-statement

我在php.net网站上关注准备好的声明示例,我似乎无法让我的版本工作。

$link = mysql_connect("localhost","root","mypassword") or die (mysql_error());

$query= $link->prepare("select * from users WHERE userid = ? AND password=password('?')");
$query->bindParam(1, $userid);
$query->bindParam(2, $password);
$query->execute();

if (mysql_num_rows($query)==1)
    {
        echo "Welcome, ",$userid,"\n";
    }
    mysql_close($link);

我收到错误:语法错误,意外的T_VARIABLE

3 个答案:

答案 0 :(得分:3)

使用mysqli_*$link = mysqli_connect(...

答案 1 :(得分:1)

更改echo "Welcome, ",$userid,"\n";

echo "Welcome, " . $userid . "\n";

答案 2 :(得分:0)

更改以下代码

` echo "Welcome, ",$userid,"\n";`

进入

` echo "Welcome, " . $userid . "\n";`

这是因为,PHP使用'。'来连接字符串。