tecmeister
08-13-2008, 01:16 AM
Hi everyone,
I'm having trouble loading the image that i have stored in mySQL.
I'm getting a header error and loads of symbols:
Warning: Cannot modify header information - headers already sent by (output started at /home/sites/onestopremovalsshop.co.uk/public_html/shop.php:9) in /home/sites/onestopremovalsshop.co.uk/public_html/shop.php on line 174
This is the script that i have used to send the image to mySQL if it helps:
<?
$dbhost = "localhost";
$dbname = "********";
$dbuser = "********";
$dbpass = "********";
$connect = mysql_connect ($dbhost, $dbuser, $dbpass) or die("CAN NOT CONNECT:".mysql_error());
mysql_select_db ($dbname);
$name = $_POST['name'];
$des = $_POST['des'];
$no = $_POST['no'];
$price = $_POST['price'];
if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) {
// Temporary file name stored on the server
$tmpName = $_FILES['image']['tmp_name'];
// Read the file
$fp = fopen($tmpName, 'r');
$data = fread($fp, filesize($tmpName));
$data = addslashes($data);
fclose($fp);
// Create the query and insert
// into our database.
$query = "INSERT INTO image(image, name, des, no, price) VALUES ('$data','$name', '$des', '$no', '$price')";
$results = mysql_query($query, $connect);
// Print results
print "Thank you, your image and data has been uploaded.";
}
else {
print "No image selected/uploaded";
}
mysql_close($connect);
?>
This is the code that i am using to view the image and data. I have know problem viewing the data just image.
<?php
$host="localhost";
$username="web180-shop-1";
$password="ryan2008";
$db_name="web180-shop-1";
$tbl_name="image";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name ORDER BY id DESC";
$result=mysql_query($sql);
?>
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td width="4%" align="center" bgcolor="#0000FF"><strong class="style4">#</strong></td>
<td width="12%" align="center" bgcolor="#0000FF"><strong class="style4">Name</strong></td>
<td width="8%" align="center" bgcolor="#0000FF"><strong class="style4">Price</strong></td>
<td width="7%" align="center" bgcolor="#0000FF"><strong class="style4">No of</strong></td>
<td width="69%" align="center" bgcolor="#0000FF"><span class="style4"><strong>Discription</strong></span></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){ // Start looping table row
?>
<tr>
<td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['name']; ?><BR></td>
<td align="center" bgcolor="#FFFFFF">£ <? echo $rows['price']; ?></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['no']; ?></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['des']; ?></td>
<? header('Content-type: image/jpg'); ?>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['image]; ?></td>
</tr>
<?php
// Exit looping and close connection
}
mysql_close();
?>
</table>
Thanks for the help that you may be able to give me.
I'm having trouble loading the image that i have stored in mySQL.
I'm getting a header error and loads of symbols:
Warning: Cannot modify header information - headers already sent by (output started at /home/sites/onestopremovalsshop.co.uk/public_html/shop.php:9) in /home/sites/onestopremovalsshop.co.uk/public_html/shop.php on line 174
This is the script that i have used to send the image to mySQL if it helps:
<?
$dbhost = "localhost";
$dbname = "********";
$dbuser = "********";
$dbpass = "********";
$connect = mysql_connect ($dbhost, $dbuser, $dbpass) or die("CAN NOT CONNECT:".mysql_error());
mysql_select_db ($dbname);
$name = $_POST['name'];
$des = $_POST['des'];
$no = $_POST['no'];
$price = $_POST['price'];
if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) {
// Temporary file name stored on the server
$tmpName = $_FILES['image']['tmp_name'];
// Read the file
$fp = fopen($tmpName, 'r');
$data = fread($fp, filesize($tmpName));
$data = addslashes($data);
fclose($fp);
// Create the query and insert
// into our database.
$query = "INSERT INTO image(image, name, des, no, price) VALUES ('$data','$name', '$des', '$no', '$price')";
$results = mysql_query($query, $connect);
// Print results
print "Thank you, your image and data has been uploaded.";
}
else {
print "No image selected/uploaded";
}
mysql_close($connect);
?>
This is the code that i am using to view the image and data. I have know problem viewing the data just image.
<?php
$host="localhost";
$username="web180-shop-1";
$password="ryan2008";
$db_name="web180-shop-1";
$tbl_name="image";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name ORDER BY id DESC";
$result=mysql_query($sql);
?>
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td width="4%" align="center" bgcolor="#0000FF"><strong class="style4">#</strong></td>
<td width="12%" align="center" bgcolor="#0000FF"><strong class="style4">Name</strong></td>
<td width="8%" align="center" bgcolor="#0000FF"><strong class="style4">Price</strong></td>
<td width="7%" align="center" bgcolor="#0000FF"><strong class="style4">No of</strong></td>
<td width="69%" align="center" bgcolor="#0000FF"><span class="style4"><strong>Discription</strong></span></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){ // Start looping table row
?>
<tr>
<td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['name']; ?><BR></td>
<td align="center" bgcolor="#FFFFFF">£ <? echo $rows['price']; ?></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['no']; ?></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['des']; ?></td>
<? header('Content-type: image/jpg'); ?>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['image]; ?></td>
</tr>
<?php
// Exit looping and close connection
}
mysql_close();
?>
</table>
Thanks for the help that you may be able to give me.