我想从 MySQL 数据库中获取一个值并将其放入 PHP 变量中。
我试过这个:
$data = mysql_query("SELECT userid FROM ao_user " .
"WHERE username = '{$this->_username}' " .
"AND password = '{$this->_password}' AND display = '{$this->_display}'");
代码显示用户名/密码无效。
这是用户登录代码:
<?php
$username = "Nynex71";
mysql_connect("localhost", "root", "test") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());
$result = mysql_query("SELECT display FROM ao_user " .
"WHERE username = '{$username}'") or die(msyql_error());
$row = mysql_fetch_assoc($result);
echo $row['display'];
?>
和
public function getDisplay()
{
mysql_connect("localhost", "root", "test") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());
$result = mysql_query("SELECT display FROM ao_user " .
"WHERE username = '{$this->_username}'");
$row = mysql_fetch_assoc($result);
$this->_display = $row['display'];
$_SESSION['display'] = $this->_display;
}
该程序不会将任何单词放入 PHP 变量中。我做错了什么,你是怎么做到的?