want to insert then view images

  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

i was speaking to someone and they said for what i want to do its not bad to store the image on the database. so that is what i want to do. i have the code for it but something is wrong. i wonder if you can help me out on this.

PHP Code: [ Select ]
<body>
 
<?php
 
//$db = mysql_connect_db("localhost","","");
 
$db=mysql_connect('localhost','root');
 
mysql_select_db("danny",$db);
 
$imageid = isset( $_GET['imageID'] ) ? $_GET['imageID'] : '';
 
//$imageid; //contains the unique_id of the required image
 
$sql="SELECT * FROM imageslinks WHERE imageID='$imageid'";
 
$res=mysql_query($sql) or die(mysql_error());
 
$row=mysql_fetch_array($res, MYSQL_ASSOC);
 
print('<img src="http://localhost/images/'.$sql.'" />');
 
?>
 
</body>
  1. <body>
  2.  
  3. <?php
  4.  
  5. //$db = mysql_connect_db("localhost","","");
  6.  
  7. $db=mysql_connect('localhost','root');
  8.  
  9. mysql_select_db("danny",$db);
  10.  
  11. $imageid = isset( $_GET['imageID'] ) ? $_GET['imageID'] : '';
  12.  
  13. //$imageid; //contains the unique_id of the required image
  14.  
  15. $sql="SELECT * FROM imageslinks WHERE imageID='$imageid'";
  16.  
  17. $res=mysql_query($sql) or die(mysql_error());
  18.  
  19. $row=mysql_fetch_array($res, MYSQL_ASSOC);
  20.  
  21. print('<img src="http://localhost/images/'.$sql.'" />');
  22.  
  23. ?>
  24.  
  25. </body>


sql code

Code: [ Select ]
CREATE TABLE imageslinks (
imageID mediumint(8) unsigned NOT NULL auto_increment,
imageLink varchar(250) NOT NULL,
name varchar(255) not null,
address varchar(255),
PRIMARY KEY (imageID),
) TYPE=MyISAM AUTO_INCREMENT=1;
  1. CREATE TABLE imageslinks (
  2. imageID mediumint(8) unsigned NOT NULL auto_increment,
  3. imageLink varchar(250) NOT NULL,
  4. name varchar(255) not null,
  5. address varchar(255),
  6. PRIMARY KEY (imageID),
  7. ) TYPE=MyISAM AUTO_INCREMENT=1;
  • stinger
  • Graduate
  • Graduate
  • stinger
  • Posts: 157
  • Loc: San Jose, CA

Post 3+ Months Ago

Usually when you connect to a database you need a username and password.

I would store you images in a folder and give that folder specific read privilages to the owner. And then you can view the images only from a specific page with read privilages.

But, if you want to use a database then thats your choice. Sorry I couldn't help more
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

i wastold that this code was ok but for one small point. big enuff to spoil the whole code and render it not working. something to do with the actual php code. can someone help me on this please,
  • stinger
  • Graduate
  • Graduate
  • stinger
  • Posts: 157
  • Loc: San Jose, CA

Post 3+ Months Ago

Code: [ Select ]
$imageid = isset( $_GET['imageID'] ) ? $_GET['imageID'] : '';


I know this line is incorrect. the ending of

Code: [ Select ]
] : '';
[/code]

has a " . This is a problem when not correctly used. example:

Code: [ Select ]
print("this is a example of proper useage");


Good luck
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

sorry but you got it wrong there. i have other codes where i have used exactly the same $_GET['imageID'] : ''; (single quotes) and it works fine. problem i am having is that the images dont work. i have got this type of coding working fully on text within tables and they work fine.

so i know for sute thats not it but thanks anyway
  • stinger
  • Graduate
  • Graduate
  • stinger
  • Posts: 157
  • Loc: San Jose, CA

Post 3+ Months Ago

Ok, I see it now. My mistake. . .

on your page, do the images come up blank? As if the variable was returned as nothing?

Or, are your image names strings that contain spaces that don't finish?
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

the image comes up blank. the source code looks like this:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
-->
</style>
</head>

<body>
<img src="http://localhost/images/" /></body>
</html>

i dont know what is happening.

it seems that there is osmething wrong with the php code. its not passing the imageid at all.
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

do i need to include the image blob thing to my code or is it something else entirely?
  • stinger
  • Graduate
  • Graduate
  • stinger
  • Posts: 157
  • Loc: San Jose, CA

Post 3+ Months Ago

Ok,
Lets try some basic trouble shooting.

Insert a

Code: [ Select ]
print("$sql\n\n\n<br>");


right after
Code: [ Select ]
$sql="SELECT * FROM imageslinks WHERE imageID='$imageid'";


This will show you if your getting the image source. If that works properly, and you recieve something like "uploaded/image.gif" then we'll know that it is getting the proper info from the database. If it returns with a blank return line we know its blank.

You might also want to run a test to view the $imageid and make sure this is set properly. IF you are submitting the image lookup through a form, I would use a echo or print statement to check the submitted variables.

Hopefully you find something!
I'll be here!
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

this is the code i have:

<?php
$db=mysql_connect('localhost','root') or die('DB ERROR: Could not connect<br />');
mysql_select_db("danny",$db) or die('DB ERROR: Could not select DB');
$imageid = isset( $_GET['imageID'] ) ? $_GET['imageID'] : '';
echo('Image ID "'.$imageid.'"<br />');
$imageid;
$res=mysql_query("SELECT * FROM imageslinks WHERE imageid='$imageid'",$db) or die('DB ERROR: '.$sql.'<br />'.mysql_error().'<br />');
print_r($_GET);
//}
?>

and this is what the browser puts out:

Image ID ""
Array ( [id] => 1 )

what can i do about that?
  • stinger
  • Graduate
  • Graduate
  • stinger
  • Posts: 157
  • Loc: San Jose, CA

Post 3+ Months Ago

Change your echo statement to read:
Code: [ Select ]
echo("Image ID : $imageid\n\n");


If you get the same thing, then your not pulling the info out of the database correctly. Download the database and view your submissions. You'll also want to check your $_GET['imageID'] variable now. So, use another echo statment like:

Code: [ Select ]
echo("search string is : $_GET['imgaeID']");


Lets see how that works!
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

i dont know what i am doing wrong. i have no idea why the database isnt connecting.. i have a text equivalent table and i get no probs with that. something is not happening.

big HELP needed
  • stinger
  • Graduate
  • Graduate
  • stinger
  • Posts: 157
  • Loc: San Jose, CA

Post 3+ Months Ago

Don't be frustrated! This is really good news. All we/you have to do now, is find a good database connect code, and then change 2 attributes!

Also, did you download the database? Try double checking the password for any gramatical errors.

I'll be back. . . . I have yahoo if your interested in instant messaging.
sn: bigjockguy
  • stinger
  • Graduate
  • Graduate
  • stinger
  • Posts: 157
  • Loc: San Jose, CA

Post 3+ Months Ago

OK, proper mysql connect code, from php.net:

Code: [ Select ]
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
  die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
  1. <?php
  2. $link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
  3. if (!$link) {
  4.   die('Could not connect: ' . mysql_error());
  5. }
  6. echo 'Connected successfully';
  7. mysql_close($link);
  8. ?>


all you need to change here is : 'mysql_user', 'mysql_password');

DON'T POST YOUR USER AND PASSWORD IN HERE!
if you want to create a new database for testing thats fine. . .use generic terms like, mypassword, and myuser as paswords etc. . . .

You'r almost there.
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

i have it running on my machine. i have php/mysql/apache running on my xp home. have had that for the past few months. regularly use it for testing. this is the first time this is happening
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

i tried ya code, ammended for my database and it worked.

Connected successfully
  • stinger
  • Graduate
  • Graduate
  • stinger
  • Posts: 157
  • Loc: San Jose, CA

Post 3+ Months Ago

Great! Do you still have problems viewing the images? Or is your project now complete?

Its a good feeling to get it right!
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

i got it to work. a friend looked at it and changed one line (i think)

$imageid = isset( $_GET['id'] ) ? $_GET['id'] : ''; that isnt in the database at all. is that a reserved statement or something?
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

ok, a serious question!!

is there a way i can make the image that is retrieved fromn the database via the id=? an actual link to.....eg a bigger/higher resolutioned picture? or is that beyond php/mysql?
  • stinger
  • Graduate
  • Graduate
  • stinger
  • Posts: 157
  • Loc: San Jose, CA

Post 3+ Months Ago

Yes. You can do it. The problem is thinking of how to get it done. If you were using .jpg for you files, this would be a lot easier! check out
http://www.room3art.com

This site does not use a database at all. I created it. View the projects section, this uses a php script to resize all the .jpg images to become thumbnails. works great!

It depends on how you want to view the image. I usually create a php page that I will pass the variable to. This page will contain a format for view the image. This format is usually just a table, with my logo, and a back link. pretty simple stuff. Let me know what exactly your doing. .
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

well i got images on the site which will be jpgs. i want the jpgs to link to their counterparts which are bigger in resolution/size. they will apear in a separate window. so basically i want to position the photo and use it as a hotspot link

but the way. i had the mistake in my code spotted out to me. i feel very stupid coz it was really simple.
$imageid = isset( $_GET['imageid'] ) ? $_GET['imageid'] : '' the imageid should have been the same as imagetryout.php?id=2

it didnt work because i was using id=2 instead of imageid=2. so everything was fine but for that linew. i felt so stupid
  • stinger
  • Graduate
  • Graduate
  • stinger
  • Posts: 157
  • Loc: San Jose, CA

Post 3+ Months Ago

Great! Well done. Ok, to set your images up, I would find the script for creating thumbnails for jpg images.

http://phpthumb.sourceforge.net/

try their thumbnail script. Your code should look something like this:

Code: [ Select ]
print("<table><tr><td>
<a href=viewimages.php?show=$src_[imageid]>
<img src=phpthumbnail.php?image=$src_[imageid]>
</a></td></tr></table>
  1. print("<table><tr><td>
  2. <a href=viewimages.php?show=$src_[imageid]>
  3. <img src=phpthumbnail.php?image=$src_[imageid]>
  4. </a></td></tr></table>


This creates a simple html table and places the image in it. The href goes to another php page that is formatted to your liking. The img src is set to display through the thumbail php script. This works great for me and saves a lot of time!!
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

how does this work? is this a different mysql query or is this just php? do i need to load the images into my existing database. if i do then it will muck up the text. not sure how its all going to fit with regards to the sql. i understand the php code and what it does but the php has to get the images from the database [imageid]. do i mage another database to get the images from? otherwise it will affect the text because some of the pictures will be in the same row as the text
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

looking at your code it looks like you have 2 database tables. one for the thumbnails and one for the the larger pics. so basically thumbnail1 = largepic1 for smooth runnings
  • stinger
  • Graduate
  • Graduate
  • stinger
  • Posts: 157
  • Loc: San Jose, CA

Post 3+ Months Ago

The code is quite simple. First you have a href tag for a html link to your php page that will display the image. Then you have the img src tag inside the href tag. NOW, both of these will use the same image url.

Code: [ Select ]
<a href=section.php?img=users/2003/Art2/Endangered_Species/wcink1.jpg&nxt=users/2003/Art2/Endangered_Species target=main>
<img src="./gen.php?users/2003/Art2/Endangered_Species/wcink1.jpg" width=75 border=0></a>
  1. <a href=section.php?img=users/2003/Art2/Endangered_Species/wcink1.jpg&nxt=users/2003/Art2/Endangered_Species target=main>
  2. <img src="./gen.php?users/2003/Art2/Endangered_Species/wcink1.jpg" width=75 border=0></a>


This is my code. In the href and img src you'll notice that I use my variable after the ? This is the same on both. But, I am using gen.php? to create the thumbnail. The href is to another php page, that will display the image in a table with next/back buttons.

http://www.room3art.com - click on projects
This is where I use gen.php to display all my thumbnails.
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

ok, on a different note (cheers for that. i will use it) i have buttons with a rollover effect. what is the best way to input the php linking there? can i just put the php link in the html file (php iradicates the need for IFrames) or can it be done in a different and better way?
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

i have a html template that i will use as the basis for my php/mysql data. i am sure that i can slot little bits of php coding into the relative tables in order for the right data to show. a little confused because i have some buttons in 1 table cell but i want the info to appear in 2 other table cells. i think the button links will have the view.php?id=2 depending on what row of info i want and the tables will have the php coding like this:

while ($myrow = mysql_fetch_array($result))
{
echo $myrow["relative_info"];
}

am i on the right track here?
  • stinger
  • Graduate
  • Graduate
  • stinger
  • Posts: 157
  • Loc: San Jose, CA

Post 3+ Months Ago

This is correct.

When I echo a variable, I always like to format it.

so, I would change :


Code: [ Select ]
while ($myrow = mysql_fetch_array($result))
{
echo $myrow["relative_info"];
}
  1. while ($myrow = mysql_fetch_array($result))
  2. {
  3. echo $myrow["relative_info"];
  4. }

To this:

Code: [ Select ]
echo("<table cellpadding=3 cellspacing=0 border=0.");
while ($myrow = mysql_fetch_array($result))
{
$myData = $myrow["relative_info"];
echo ("<tr><td>$myData</td></tr>");
}
  1. echo("<table cellpadding=3 cellspacing=0 border=0.");
  2. while ($myrow = mysql_fetch_array($result))
  3. {
  4. $myData = $myrow["relative_info"];
  5. echo ("<tr><td>$myData</td></tr>");
  6. }


This will put the data into a table and then you can control how its formatted, aligned, etc. . Otherwise your variables will just be listed .
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

i am trying to have some table elements out of the php area and some inside the php area. is this possible at all? or must you have the complete table within the php area?
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

for instance can i have this arrangement?

<table><tr><td>some stuff here</td></tr><tr><td><?php while ($myrow = mysql_fetch_array($result))
{
$myData = $myrow["relative_info"];
echo $myData);
}
</td></tr></table>

Post Information

  • Total Posts in this topic: 39 posts
  • Users browsing this forum: No registered users and 74 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.