我正在建立一个网站来学习编码。我有一个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,
现在继承了claim.php的代码,该代码将公司ID发送到addclaimedbiz.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);
?>
答案 0 :(得分:2)
你没有在字符串中使用正确的变量插值,将$business_name
放在qutoes中:
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_ *函数上讲课。 :)
干杯
答案 1 :(得分:1)
您需要将字符串连接起来,如下所示:
echo "You are claiming:" . $business_name . " as your business";
答案 2 :(得分:1)
我认为您需要在.
声明中添加一些echo
。
像这样:
echo "You are claiming: " . $business_name . " as your business";
答案 3 :(得分:0)
你需要使用。连接php中的字符串
echo "You are claiming:".$business_name ". as your business"