gpt4 book ai didi

PHP Select语句与mysql的问题

转载 作者:行者123 更新时间:2023-11-29 08:21:22 25 4
gpt4 key购买 nike

Php Select 语句与 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);

关于PHP Select语句与mysql的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19304670/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com