Note that there are some explanatory texts on larger screens.

plurals
  1. POIssue with MySQL Select
    primarykey
    data
    text
    <p>I'm building a website to learn coding. I have a claim.php which is a claim your business page (its just a place that you can search for a business and then click a link to addclaimedbiz.php) and a addclaimedbiz.php page which adds the claimed business to the database.</p> <p>First of all, heres my sql code for the user where the business id will be added to the row <strong>biz</strong>:</p> <pre><code>`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, </code></pre> <p>and heres my sql code for the businesses:</p> <pre><code>`id` int(15) NOT NULL AUTO_INCREMENT, `name` varchar(50) NOT NULL, `phone` varchar(14) NOT NULL, `claimed` int(1) NOT NULL, </code></pre> <p>Now heres the code for claim.php that sends the company id to addclaimedbiz.php. ( I only posted a little but can post more if you need it!)</p> <pre><code> 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" &lt;div class='listing'&gt; &lt;li&gt; &lt;span class='bphone'&gt;$company_phone&lt;/span&gt; &lt;span class='bname'&gt;$company_name&lt;/span&gt; &lt;br/&gt; &lt;div class='blocation'&gt;$company_address, $company_city, CO $company_zip ";if($address2 != ""){echo"(".$address2.")";}echo"&lt;/div&gt; &lt;br/&gt; ";if($claimed != 1){echo "&lt;a href='addclaimedbiz.php?id=".$id."'&gt;&lt;button&gt;Claim Business&lt;/button&gt;&lt;/a&gt;";}else{echo "Already Claimed";}echo" &lt;/li&gt; &lt;!--/Listing--&gt; &lt;/div&gt;"; } </code></pre> <p>And then heres my code for addclaimedbiz.php:</p> <pre><code> &lt;? $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']; } ?&gt; </code></pre> <p>and then to echo out $business_name i use (this is on addclaimedbiz.php as well just down the page a bit)</p> <pre><code>&lt;?php if($biz == "0"){ echo "You are claiming:"$business_name " as your business"; } else{"You are already have a claimed business"} ?&gt; </code></pre> <p>What should be happening is it should echo out You are claiming: $business_name as your business but right now its leaving out $business_name. Why is this?</p> <p>Major thanks to all help!</p> <p>Oh and I left out some of the rows in my databases that were unnecessary to the problem I thought, but if you need them I can definitely post!</p> <hr> <p>EDIT</p> <hr> <p>my new code looks like this:</p> <pre><code>&lt;? 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); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload