对不起..我只想稍早澄清一下我的帖子。
<?php
$db = pg_connect("host=localhost dbname=dbname user=user password=password");
$sql = "SELECT * FROM users WHERE user_id = 8320 AND password = 'admin' ";
$query = pg_query($sql);
$row = pg_fetch_array($query);
var_dump($row); //DUMPS EXACTLY WHAT I WANTED.. BUT WHEN I put it on a function like this.
?>
<?php
function checkLogin($user_id, $password)
{
$db = pg_connect("host=localhost dbname=dbname user=user password=password");
$sql = "SELECT * FROM users WHERE user_id = $user_id AND password = $password ";
$query = pg_query($sql);
$row = pg_fetch_array($query);
return $row;
}
?>
//CALL HERE
$ data = checkLogin(8320,'admin'); 的var_dump($数据); //转储NULL
为什么会这样?
答案 0 :(得分:1)
您传递的密码值$upassword
并使用$password
字符串应附带引号,如下所示
"SELECT * FROM users WHERE user_id = $user_id AND password = '$password'"
答案 1 :(得分:0)
问题在这里......
function checkLogin($user_id, $upassword) //passing $upassword not $password
你传递$upassword
但是之后不要使用它,而是使用..只是$password
$sql = "SELECT * FROM users WHERE user_id = $user_id AND password = '$password'";
更改为...
$sql = "SELECT * FROM users WHERE user_id = $user_id AND password = '$upassword'";
简单忽略的语法错误:)
答案 2 :(得分:0)
$sql = "SELECT * FROM users WHERE user_id = $user_id AND password = $password ";
should be
$sql = "SELECT * FROM users WHERE user_id = $user_id AND password = '$password' ";
答案 3 :(得分:-1)
跟进Vinoth的回答,如果$ user_id将是一个需要用引号括起来的字符串。并且要小心清理用户提交的输入。