Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

- - - - -

Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

mysql

  • This topic is locked This topic is locked
213 replies to this topic

#193 kirigwajoe

kirigwajoe

    CC Lurker

  • Just Joined
  • Pip
  • 9 posts

Posted 26 January 2011 - 11:18 PM

thank u
  • 0

#194 whitestar

whitestar

    CC Regular

  • Just Joined
  • PipPipPip
  • 33 posts

Posted 07 February 2011 - 04:10 AM

Is there a way to set the size that the image is displayedEg length and width of the image?
  • 0

#195 sohels2

sohels2

    CC Lurker

  • Just Joined
  • Pip
  • 3 posts

Posted 09 February 2011 - 04:43 PM

I am getting the following error, can someone help please.

Warning: Cannot modify header information - headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/insert.php:3) in /Applications/XAMPP/xamppfiles/htdocs/insert.php on line 76
  • 0

#196 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 09 February 2011 - 05:34 PM

I am getting the following error, can someone help please.

It would appear you are printing something to the browser before you call the function that sends the header(), this can include whitespace.
  • 0

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.


#197 sohels2

sohels2

    CC Lurker

  • Just Joined
  • Pip
  • 3 posts

Posted 09 February 2011 - 08:34 PM

I am getting the following error, can someone help please.

Warning: Cannot modify header information - headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/insert.php:3) in /Applications/XAMPP/xamppfiles/htdocs/insert.php on line 76


so i fixed the printing problem but now its showing :

" Please select your image!"

So i guess its not fetching the image from the server at $id = $_GET['id'];

Thank you.
  • 0

#198 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 09 February 2011 - 09:17 PM

Are you accessing the image through script.php?id=(some number)?
  • 0

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.


#199 sohels2

sohels2

    CC Lurker

  • Just Joined
  • Pip
  • 3 posts

Posted 10 February 2011 - 08:12 AM

I am using the exact same script provided above.


<?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'];

if(!isset($id) || empty($id) || !is_int($id)){
die("Please select your image!");
}else{

$query = mysql_query("SELECT * FROM tbl_images WHERE id='".$id."'");
$row = mysql_fetch_array($query);
$content = $row['image'];

header('Content-type: image/jpg');
echo $content;
}
?>

I am trying to load an image and have it shown right away, like they do it on craigslist when u posting an add.

Thank you.
  • 0

#200 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 10 February 2011 - 10:06 PM

Then you need to pass the id part of the query to the next page, when you upload it. You can get the last inserted ID (for the ?id=xxx) with mysql_insert_id().
  • 0

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.


#201 whitestar

whitestar

    CC Regular

  • Just Joined
  • PipPipPip
  • 33 posts

Posted 11 February 2011 - 01:25 AM

Hello

I need a little help I want to change the table and insert.php script a little bit. I’ve changed the table (images) that holds the images by adding a column called subscriber I have another table called subscriber_info that all the subscriber info is on but what I want to do is when I add the image I want to also record the subscriber_id into the subscriber column on the images table at the same time so that I know who added the picture and also so that I can create a page where all the subscribers can view all of the images that they have uploaded.
I have this script on my add.html page
<form action="insert.php" method="post" enctype="multipart/form-data" name="browse" id="brows_form">

<div align="left">
<input type="hidden" name="MAX_FILE_SIZE" value="102400" >
<input name="image" type="file" class="style1" accept="image/jpeg" />
<input type="hidden" name="subscriber " value="<?php echo $row_subscriber_username['subscriber_id']; ?>" />
<input type="submit" value="Upload" >
<span class="style10">Choose Your Profile Picture</span></div>
</form>

And this script on my insert.php page
<?php

$username = "root";
$password = "159753";
$host = "localhost";
$database = "the_secrets_out";
$table = "images";
$column = "image";


$link = mysql_connect($host, $username, $password); if (!$link) {
die("Can not connect to database: ".mysql_error());
}

mysql_select_db ($database);

if (isset($_FILES[$column]) && $_FILES[$column]['size'] > 0) {

$tmpName = $_FILES[$column]['tmp_name'];

$fp = fopen($tmpName, 'r');
$data = fread($fp, filesize($tmpName));
$data = addslashes($data);
fclose($fp);

$query = "INSERT INTO $table ";
$query .= "($column) VALUES ('$data')";
$results = mysql_query($query, $link);

print "Thank you, Your Image has been uploaded. DONT FORGET to add the image into your profile! ";

}
else {
print "No image selected/uploaded. Make sure that you have not exceeded the max file size!";
}

mysql_close($link);
?>

What do I need to change on the insert.php script to fetch the subscriber_id and insert it into the subscriber column?
  • 0

#202 kwahedi

kwahedi

    CC Newcomer

  • New Member
  • PipPip
  • 10 posts

Posted 13 February 2011 - 01:39 AM

Thanks Dear jaan!!!
in your code you have written there
we can display the stored image from the database but it took the whole page
actually i want to display it inside of the table <td>
so how can i do this
can u dig out this for me
  • 0

#203 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 13 February 2011 - 03:14 AM

Thanks Dear jaan!!!
in your code you have written there
we can display the stored image from the database but it took the whole page
actually i want to display it inside of the table <td>
so how can i do this
can u dig out this for me


Assuming your display page is show.php, you can use <td><img src="show.php?id=4"/></td>.

Is that what you mean? Or display all images in a single table?
  • 0

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.


#204 kwahedi

kwahedi

    CC Newcomer

  • New Member
  • PipPip
  • 10 posts

Posted 14 February 2011 - 11:23 PM

Dear Alexander!!!
let me to show you all my code
===============
display.php
---------
<form action="show.php" method="Get">
<input name="id" type="text">
<input type="submit" value="find">
</form>
=======================================

show.php
--------
<?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'];

if(!isset($id) || empty($id)){
die("Please select your image!");
}else{

$query = mysql_query("SELECT * FROM table_name WHERE id='".$id."'");
$row = mysql_fetch_array($query);
$content = $row['Photo'];

header('Content-type: image/jpg');
echo $content;

}

?>



This is the whole code that ai am using
now i want to shwo the result of the query inside of the table <td>
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download