私信  •  关注

derokorian

derokorian 最近创建的主题
derokorian 最近回复了
$result = mysql_query('SELECT * FROM Users WHERE UserName LIKE $username');

使用单引号定义字符串,php不解析单引号分隔的字符串。为了获得变量插值,您需要使用双引号或字符串连接(或其组合)。见 http://php.net/manual/en/language.types.string.php 更多信息。

您还应该检查mysql_query是否返回了有效的结果资源,否则fetch_*、num_rows等将无法处理结果,因为这不是结果!IE:

$username = $_POST['username'];
$password = $_POST['password'];
$result = mysql_query('SELECT * FROM Users WHERE UserName LIKE $username');

if( $result === FALSE ) {
   trigger_error('Query failed returning error: '. mysql_error(),E_USER_ERROR);
} else {
   while( $row = mysql_fetch_array($result) ) {
      echo $row['username'];
   }
}

http://us.php.net/manual/en/function.mysql-query.php 更多信息。