Jump to content

[SOLVED] Can someone spot the error?


englishcodemonkey

Recommended Posts

When i run this code nothing shows in the table...Well i guess the table doesn't even show up!  I was told this was because of the SQL connection or query?? I know my connection is correct because I have other PHP scripts running correctly from it??  Here is how my table is set up.  This is confusing me because I had it working perfect on localhost.

 

CREATE TABLE HOSTA (
hosta_id INT AUTO_INCREMENT PRIMARY KEY,
hosta_name VARCHAR(50) NOT NULL,
hybridizer VARCHAR(50),
size VARCHAR(10),
description VARCHAR (200),
price DECIMAL(3,2));

 

 

 

<?php
require_once('conn.php');

$hosta = $_REQUEST['hosta'];
$hosta1 = $_REQUEST['hosta'];

$q = "SELECT hybridizer, size, price, description from hostajess where hosta_name='$hosta'";

$r = @mysqli_query ($dbc, $q);


if ($r) {


echo '
	<table align="center" cellspacing="3" cellpadding="3" width="75%">
		<tr>
			<td align="left" width="33.3%">Hybridizer</td>
			<td align="left" width="33.3%">Size</td>
			<td align="left" >Price</td>
		</tr>';

while ($row = mysqli_fetch_array($r,MYSQLI_ASSOC)) {
	echo '
		<tr>
			<td align="left">' .$row['hybridizer'] . '</td>
			<td align="left">' .$row['size'] . '</td>
			<td align="left">' .$row['price']. '</td>
		</tr>';
}
}

echo '</table>';

$q = "SELECT description from hostajess where hosta_name='$hosta1'";
$r = mysqli_query ($dbc, $q);

if ($r) {


echo '
	<table align="center" cellspacing="3" cellpadding="3" width="75%">
		<tr>
			<td align="left">Description</td>
		</tr>';

while ($row = mysqli_fetch_array($r,MYSQLI_ASSOC)) {
	echo '
		<tr>
			<td align="justify">' .$row['description'] . '</td>
		</tr>';
}
}

echo '</table>';



mysqli_close($dbc);


?>

 

This is really frustrating me! thanks for all your help!  :)

Link to comment
Share on other sites

The table on my local MySQL is called 'hosta'. The table I created on my host is called 'hostajess'.  I posted the code that I used to set up the table because that has the fields in, forgetting that I had changed the name.  The code for the table should have been posted as:

 

CREATE TABLE hostajess (
hosta_id INT AUTO_INCREMENT PRIMARY KEY,
hosta_name VARCHAR(50) NOT NULL,
hybridizer VARCHAR(50),
size VARCHAR(10),
description VARCHAR (200),
price DECIMAL(3,2));

 

Sorry for the confusion!

Link to comment
Share on other sites

you need to do the error function as:

 

$result = mysql_query("QUERY") or die(mysql_error());

that should show the error

 

 

also, when you get the blank page, view the source and see if anything is printing. Like the </table> tag that  you have set to output whether $r is true or not. If it does display, then there's an error grabbing the data. If it's blank, then you have error in the code.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.