Connect with Facebook Lost Password?


Go Back   CodeCall Programming Forum > Software Development > Tutorials > PHP Tutorials

PHP Tutorials PHP Tutorials

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #31 (permalink)  
Old 11-20-2008, 02:58 PM
Xav's Avatar   
Xav Xav is offline
Code Slinger
 
Join Date: Mar 2008
Location: The North Pole
Posts: 13,210
Blog Entries: 13
Rep Power: 105
Xav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud of
Send a message via MSN to Xav
Default Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

The ? indicates the GET arguments. Then you have name/value pairs, joined with the = symbol and separated from other pairs via the & symbol.
__________________

Quote:
Originally Posted by Jordan View Post
Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #32 (permalink)  
Old 12-16-2008, 09:10 AM
Newbie
 
Join Date: Dec 2008
Posts: 5
Rep Power: 0
sanyal is an unknown quantity at this point
Default Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

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

PHP 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;

}

?>
thanks in advance.....waiting for the response..!

Last edited by Jaan; 12-16-2008 at 09:39 AM.. Reason: Please use code tags when you're posting your codes!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #33 (permalink)  
Old 12-16-2008, 03:56 PM
Jordan's Avatar   
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Posts: 18,359
Blog Entries: 90
Rep Power: 20
Jordan is a glorious beacon of lightJordan is a glorious beacon of lightJordan is a glorious beacon of lightJordan is a glorious beacon of lightJordan is a glorious beacon of light
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan Send a message via Yahoo to Jordan
Default Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #34 (permalink)  
Old 12-17-2008, 03:06 AM
Newbie
 
Join Date: Dec 2008
Posts: 5
Rep Power: 0
sanyal is an unknown quantity at this point
Default Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

first of all thanks for u r .responce.........

this is the whole code..........
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>
.........i have commented that line as u said it might have already declared ..........
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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #35 (permalink)  
Old 12-17-2008, 04:39 AM
orjan's Avatar   
Guru
 
Join Date: Sep 2007
Location: Sunne, Vrmland, Sweden
Age: 34
Posts: 1,303
Blog Entries: 7
Rep Power: 18
orjan is just really niceorjan is just really niceorjan is just really niceorjan is just really nice
Send a message via MSN to orjan Send a message via Skype™ to orjan
Default Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #36 (permalink)  
Old 12-17-2008, 09:52 AM
Jaan's Avatar   
Moderator
 
Join Date: Dec 2006
Location: Estonia
Age: 18
Posts: 1,518
Blog Entries: 4
Rep Power: 24
Jaan is just really niceJaan is just really niceJaan is just really niceJaan is just really niceJaan is just really nice
Send a message via MSN to Jaan
Default Re: 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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #37 (permalink)  
Old 12-17-2008, 07:00 PM
Newbie
 
Join Date: Dec 2008
Posts: 5
Rep Power: 0
sanyal is an unknown quantity at this point
Default Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

thanks a lot to both of u jaan and orjan.............!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #38 (permalink)  
Old 12-19-2008, 12:02 PM
Jaan's Avatar   
Moderator
 
Join Date: Dec 2006
Location: Estonia
Age: 18
Posts: 1,518
Blog Entries: 4
Rep Power: 24
Jaan is just really niceJaan is just really niceJaan is just really niceJaan is just really niceJaan is just really nice
Send a message via MSN to Jaan
Default Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

Does it works now?
and no problem
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #39 (permalink)  
Old 12-20-2008, 02:13 AM
Newbie
 
Join Date: Dec 2008
Posts: 5
Rep Power: 0
sanyal is an unknown quantity at this point
Default Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

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

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;
}

?>
and if i am trying to display other data from the table by using echo....
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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #40 (permalink)  
Old 12-20-2008, 07:16 AM
orjan's Avatar   
Guru
 
Join Date: Sep 2007
Location: Sunne, Vrmland, Sweden
Age: 34
Posts: 1,303
Blog Entries: 7
Rep Power: 18
orjan is just really niceorjan is just really niceorjan is just really niceorjan is just really nice
Send a message via MSN to orjan Send a message via Skype™ to orjan
Default Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

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:
PHP 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];

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.

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tutorial: Storing Images in MySQL with PHP Jordan PHP Tutorials 23 06-02-2009 10:01 PM
Tutorial: PHP to MySQL Jordan PHP Tutorials 9 09-05-2008 12:12 PM


All times are GMT -5. The time now is 10:09 PM.

Freelance Jobs

XML/XSL: Need code for Book with Chapers using XML
Create an XML file for a book of your creation, and a basic CSS file that will format it to display ...
Earn: $40.00


C++/C: Simple firework cue sequencer
What I require is a rework of a simple cue sequencer. I have a piece of hardware (an Arduino boar...
Earn: $50.00


HTML/XHTML: Menu Rework - ASCIIBin
I'm placing this in the HTML/XHTML section of the Freelance site but you are not limited to HTML. Wh...
Earn: $20.00



CodeCall Goal

Goal #1: 1,000 Blogs
Goal #2: 1,000 Wiki Pages
Goal #3: 300,000 Posts
Goal #4: 20,000 Threads
Done: 30%, 23%, 55%, 75%

Ads