Php Select an instruction problem with mysql

收藏待读

Php Select an instruction problem with mysql

Php Select statement issue with mysql

I get this error ..

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/try/public_html/register.php on line 17

My Code is

$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 = "

Site Address " . $siteAddress . " is not available.

"; $proceed = "no"; }

I try echo $sql and I get this

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';

If i input the sql at phpmyadmin it return something..

Showing rows 0 - 0 (1 total, Query took 0.0003 sec)

you have two semi-colons there

$sql="SELECT * FROM user WHERE siteAddress='$siteAddress';";

it should be:

$sql="SELECT * FROM user WHERE siteAddress='" . $siteAddress ."'";

you can do also:

$sql= mysql_query("SELECT * FROM user WHERE siteAddress='" . $siteAddress ."'");
$count=mysql_num_rows($sql);

原文 : Hello, buddy!

相關閱讀

免责声明:本文内容来源于Hello, buddy!,已注明原文出处和链接,文章观点不代表立场,如若侵犯到您的权益,或涉不实谣言,敬请向我们提出检举。