The ? indicates the GET arguments. Then you have name/value pairs, joined with the = symbol and separated from other pairs via the & symbol.
hi.......
i am new to php...i like u r tutorial....its simple easy going....
i tried u r example of Tutorial: Storing Images in MySQL with PHP / Part II / Display your images , but i am getting this error....somthing like this
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\task\show_img.php:9) in C:\xampp\htdocs\task\show_img.php on line 30
and here is my code
thanks in advance.....waiting for the response..!Code:<?php
$username = "root";
$password = "";
$host = "localhost";
$database = "test";
@mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error());
@mysql_select_db($database) or die("Can not select the database: ".mysql_error());
//$id = $_GET['id'];
$id=2;
if(!isset($id) || empty($id)){
die("Please select your image!");
}else{
$query = mysql_query("SELECT * FROM images WHERE id='".$id."'");
$row = mysql_fetch_array($query);
$content = $row['img'];
header('Content-type: image/jpg'); =====error =====> ( line 30)
echo $content;
}
?>
Last edited by Jaan; 12-16-2008 at 09:39 AM. Reason: Please use code tags when you're posting your codes!
This error means you have already sent your headers somewhere. Do you have a space before or above <?php ? Is another script being executed first?
first of all thanks for u r .responce.........
this is the whole code..........
.........i have commented that line as u said it might have already declared ..........Code:<html> <head> <title>Untitled Document</title> <!-- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> --> </head> <body> <?php $username = "root"; $password = ""; $host = "localhost"; $database = "test"; @mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error()); @mysql_select_db($database) or die("Can not select the database: ".mysql_error()); //$id = $_GET['id']; $id=4; if(!isset($id) || empty($id)){ die("Please select your image!"); }else{ $query = mysql_query("SELECT * FROM images WHERE id='".$id."'"); $row = mysql_fetch_array($query); $content = $row['img']; header('Content-type: image/jpg'); echo $content; } ?> </body> </html>
now i am not getting the error.....but the out put...is somthing like this........
�JFIF�������C� $.' ",#(7),01444'9=82<.342�C 2!!22222222222222222222222222222222222222222222222 222�4"������������ ����}�!1AQa"q2‘#BR$3br‚ ........and so ...on
can u plzss...tell me what would b the problem.........and y is it happening so....!
thanks in advance.......
Last edited by Jaan; 12-17-2008 at 09:51 AM. Reason: Please use code tags when you're posting your codes!
As mentioned one page back in this thread, ABSOLUTELY NOTHING can be put before the "<?php" tag or after the "?>" for this script! It shall NOT have any HTML or HEAD or BODY, as it is NOT an Webpage, this is an image file you want to show.
Tutorial: Storing Images in MySQL with PHP / Part II / Display your images
you're right orjan.. You MUST NOT have anything after and before PHP tags!
█ Trill Hosting - Cheap Web Hosting, Register Cheap Domains, Cheap Blog Hosting
█ www.trillhosting.com | support@trillhosting.com
█ Hosting Plans | Write To Us | Support | Client Area | About Us
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | Freelance
thanks a lot to both of u jaan and orjan.............!
![]()
Does it works now?
and no problem![]()
█ Trill Hosting - Cheap Web Hosting, Register Cheap Domains, Cheap Blog Hosting
█ www.trillhosting.com | support@trillhosting.com
█ Hosting Plans | Write To Us | Support | Client Area | About Us
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | Freelance
hi.........
jaan........
yess its working fine........ when i am trying to displaying only one image...........but when i am trying to display all the images of the tables
then i am getting only one image that is .... the first image of the table
here is the code
and if i am trying to display other data from the table by using echo....Code:<?php $username = "root"; $password = ""; $host = "localhost"; $database = "test"; @mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error()); @mysql_select_db($database) or die("Can not select the database: ".mysql_error()); $query = mysql_query("SELECT * FROM images")or die("Cannot exe----- select the database: ".mysql_error()); while($row = mysql_fetch_array($query)){ //echo $row['id']; $content = $row['img']; header('Content-type: image/jpg'); echo $content; } ?>
say as........
echo $row['id'];---------->it is showing error
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\sun\show1.php:23) in C:\xampp\htdocs\sun\show1.php on line 28
JFIFC $.' ",#(7),01444'9=82<.342C 2!!22222222222222222222222222222222222222222222222 2224"
and can you help me in display both images and other data from MSQL using PHP script.
thanks in advance..............
Last edited by Jaan; 12-20-2008 at 07:51 AM. Reason: Please use code tags when you're posting your codes!
No. This script is made to fetch one picture at a time.
that's why we use the id in the url.
if you want to show several pictures, you would need to do this in ANOTHER script:
similar to this:
This script first adds a img-tag to the html, then prints an to the picture attached comment from the database and outputs that one too.Code:$query = mysql_query("SELECT * FROM images")or die("Cannot exe----- select the database: ".mysql_error());
while($row = mysql_fetch_array($query)){
$id = $row[id];
echo "<img src='fetch.php?id=$id'>";
echo $row[comment];
}
the filename fetch.php is just something I made up now, and is the file where the picture fetching script is in.
Conclusion, the script fetches ordered picture. if you want to fetch several pictures, you need to order each picture to be shown from your html or another phpscript
There are currently 2 users browsing this thread. (0 members and 2 guests)
Bookmarks
Algorithms and Data Structures
Java tutorials
Algorithms Forum