Jump to content

PHP Query Error


aleister1987

Recommended Posts

Hi all,

 

I have a problem, Im not so hot on PHP but here goes. I have done a query and i want the info from my database(table) in  table form in my php/html document. Here is what i have. Im also trying to echo an image stored in a sql database. At present its just a blank screen mainly.

 

<?php

$host="..."; // Host name

$username="..."; // Mysql username

$password="..."; // Mysql password

$db_name="..."; // Database name

$tbl_name="..."; // Table name

 

// Connect to server and select database.

mysql_connect("$host", "$username", "$password")or die("cannot connect");

mysql_select_db("$db_name")or die("cannot select DB");

 

// Retrieve data from database

$sql="SELECT * FROM $tbl_name";

$result=mysql_query($sql);

 

//Puts it into an array

while($info=mysql_fetch_array( $sql ))

{

echo "<table width='800' border='1' cellspacing='1' cellpadding='3'>";

echo "<tr>";

echo "<td style='border-style:solid;border-color:#ccc' bgcolor='#045C97'><font size='3' color='#fff'>Model No:</font></td>";

echo "<td style='border-style:solid;border-color:#ccc' bgcolor='#045C97'><font size='3' color='#fff'> </font></td>";

echo "<td style='border-style:solid;border-color:#ccc' bgcolor='#045C97'><font size='3' color='#fff'>Description:</font></td>";

echo "<td style='border-style:solid;border-color:#ccc' bgcolor='#045C97'><font size='3' color='#fff'>Price:</font></td>";

echo "<td style='border-style:solid;border-color:#ccc' bgcolor='#045C97'><font size='3' color='#fff'>Stock:</font></td>";

echo "</tr>";

echo "<tr>";

echo "<td>" . $info['model'] . " </td>";

echo "<td>"<img src=http://www.swiftelectrical.net/images/".$info['photo'] ."></td>";

echo "<td>" . $info['product'] . " </td>";

echo "<td>" . $info['description'] . " </td>";

echo "<td>" . $info['price'] . " </td>";

echo "<td>" . $info['stock'] . " </td>";

echo "</tr>";

echo "</table>";

}

mysql_close ();

?>

Link to comment
https://forums.phpfreaks.com/topic/203341-php-query-error/
Share on other sites

Thanks for that. However, I followed another tutorial to be able to upload images. I can echo the image fine when i take all my html off the page.

 

I have added the die function on the query.

 

But... I still have the original problem, the table itself doesn't show on the page.

Link to comment
https://forums.phpfreaks.com/topic/203341-php-query-error/#findComment-1065324
Share on other sites

You need to make s sperate page for the image, or output it as base64 encoded, which is not the option you should go for ;)

 

Just create another script, that only outputs the image from the database. You have to pay attention to the header setting:

Content-Type: image/jpeg or what ever you need.

 

Then, you will have an image tag on your original page, whose src attribute points to your newly created script for the image.

Link to comment
https://forums.phpfreaks.com/topic/203341-php-query-error/#findComment-1065341
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.