PHP选择语句问题与MySQL
我收到此错误..
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/try/public_html/register.php on line 17
我的密码是
$siteAddress = trim($_POST['b_Address']);
$sql="SELECT * FROM user WHERE siteAddress='$siteAddress';";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
//check for address
if($count)
{
$errorMessage = "<p><font color=red size=4>Site Address " . $siteAddress . " is not available. </font></p>";
$proceed = "no";
}
我尝试echo $ sql,我明白了
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/try/public_html/register.php on line 17
SELECT * FROM user WHERE siteAddress='myshop';
如果我在phpmyadmin中输入sql,则会返回一些信息。
Showing rows 0 - 0 (1 total, Query took 0.0003 sec)
最佳答案
你那里有两个分号
$sql="SELECT * FROM user WHERE siteAddress='$siteAddress';";
它应该是:
$sql="SELECT * FROM user WHERE siteAddress='" . $siteAddress ."'";
您还可以:
$sql= mysql_query("SELECT * FROM user WHERE siteAddress='" . $siteAddress ."'");
$count=mysql_num_rows($sql);