1

我正在建立一个网站来学习编码。我有一个 claim.php,它是一个声明您的业务页面(它只是一个您可以搜索业务然后单击指向 addclaimedbiz.php 的链接的地方)和一个 addclaimedbiz.php 页面,它将声明的业务添加到数据库中。

首先,这是我的用户的 sql 代码,其中业务 id 将添加到行biz

`id` int(15) NOT NULL AUTO_INCREMENT,
`firstname` varchar(50) NOT NULL,
`lastname` varchar(50) NOT NULL,
`email` varchar(75) NOT NULL,
`password` varchar(50) NOT NULL,
`biz` int(1) NOT NULL,
`verifiedbiz` int(1) NOT NULL,

这是我的企业 sql 代码:

`id` int(15) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`phone` varchar(14) NOT NULL,
`claimed` int(1) NOT NULL,

现在是将公司 ID 发送到 addclaimedbiz.php 的 claim.php 的代码。(我只发了一点,如果你需要可以发更多!)

 while($row = mysql_fetch_array($result))
            {
            $id=$row['id'];
            $company_name=$row['name'];
            $company_phone=$row['phone'];
            $company_address=$row['address'];
            $address2=$row['address2'];
            $company_city=$row['city'];
            $company_zip=$row['zipcode'];
            $cat1=$row['cat1'];
            $cat2=$row['cat2'];
            $cat3=$row['cat3'];
            $subcat1=$row['subcat1'];
            $subcat2=$row['subcat2'];
            $subcat3=$row['subcat3'];
            $claimed=$row['claimed'];
            //Start While Loop
            echo"
            <div class='listing'>
                                    <li>
                                        <span class='bphone'>$company_phone</span>
                                        <span class='bname'>$company_name</span>
                                        <br/>
                                        <div class='blocation'>$company_address, $company_city, CO $company_zip ";if($address2 != ""){echo"(".$address2.")";}echo"</div>
                                        <br/>
                                        ";if($claimed != 1){echo "<a href='addclaimedbiz.php?id=".$id."'><button>Claim Business</button></a>";}else{echo "Already Claimed";}echo"
                                    </li>

                                <!--/Listing-->

                </div>";

            }

然后是我的 addclaimedbiz.php 代码:

 <?
 $biz_id = $_REQUEST['id'];

 //This next select from db is to take the id of the company and get the name for the corresponding id

 include("./config.php");
 $result = mysql_query("SELECT * FROM company WHERE id = '$biz_id'") or die(mysql_error());
 while($row = mysql_fetch_array($result))
 {
    $business_name = $row['name'];
 }

 ?>

然后回显出我使用的 $business_name(这在 addclaimedbiz.php 上以及页面下方)

<?php if($biz == "0"){

            echo "You are claiming:"$business_name " as your business";

            }
            else{"You are already have a claimed business"}
            ?>

应该发生的是它应该回显您声称:$business_name 是您的企业,但现在它忽略了 $business_name。为什么是这样?

非常感谢所有帮助!

哦,我在我的数据库中遗漏了一些对我认为的问题来说不必要的行,但如果你需要它们,我绝对可以发布!


编辑


我的新代码如下所示:

<?
error_reporting(E_ALL);
$auth = $_COOKIE["auth"];
if ($auth != "1"){
header("Location: ./signin.php");
}
$firstname = $_COOKIE['firstname'];
$id = $_COOKIE['id'];
$fname = ucwords($_COOKIE['firstname']);
$lname = ucwords($_COOKIE['lastname']);
$email = $_COOKIE['email'];
$city = ucwords($_COOKIE['city']);
$biz = ucwords($_COOKIE['biz']);

$biz_id = $_REQUEST['id'];

include("./config.php");
$result = mysql_query("SELECT * FROM company WHERE id = '$biz_id'") or die(mysql_error());
if(mysql_num_rows($result)){
    while($row = mysql_fetch_assoc($result)){
        $business_name = $row['name'];
    }
}
echo count($result);
?>
4

4 回答 4

2

您没有在字符串中使用正确的变量插值,放在$business_name引号内:

echo "You are claiming:$business_name as your business";

啊,看起来也像你想要mysql_fetch_assoc的,而不是mysql_fetch_array

while($row = mysql_fetch_assoc($result)){
    $business_name = $row['name'];
}

文档在这里

嗯...我有一种预感,尝试用以下方式包装你的while块:

if(mysql_num_rows($result)){
   ...   
}

我会让其他人做关于 mysql_* 函数的讲座。:)

干杯

于 2012-08-03T21:50:18.653 回答
1

您需要使用句点连接字符串,如下所示:

        echo "You are claiming:" . $business_name . " as your business";
于 2012-08-03T21:49:50.340 回答
1

我相信你需要.在你的echo陈述中加入一对。

像这样:

echo "You are claiming: " . $business_name . " as your business";

于 2012-08-03T21:50:05.423 回答
0

你需要使用 . 在php中连接字符串

 echo "You are claiming:".$business_name ". as your business"
于 2012-08-03T21:52:09.587 回答