Page 2 of 2
Re: php, mysql and images ... ARGH!
Posted: Tue Apr 01, 2008 12:39 am
by nVee
thank you for ur help.
How will i now actually get the link to be stored in the database, and then later when i recall it, how will the server know its a link *how will the actual recall of the image be made*.
Thank you so much for your help so far!
Re: php, mysql and images ... ARGH!
Posted: Tue Apr 01, 2008 9:15 am
by aceconcepts
In order to insert the image into the database all you need to do is specify the name of the image file:
Code: Select all
//GET THE IMAGE NAME FROM THE UPLOAD
$imgName=$_FILES['img']['name'];
//INSERT THE DATA - NOTE THE NEW VARIABLE $imgName
$sql = "INSERT INTO bushshirts (img,name,description) VALUES ('$imgName','$name','$description')";
Now, in order to retrieve the image file and make it a link you would do:
Code: Select all
//SPECIFY WHERE THE IMAGES ARE STORED e.g. "http://www.site.com/images/uploads/"
$directory_to_uploads
//GET THE CORRECT RECORDS/PRODUCTS
$listProducts=mysql_query("SELECT * FROM bushshirts ORDER BY name");
//CHECK IF ANY PRODUCTS EXIST
if(mysql_num_rows($listProducts)>0)
{
//NOW OUTPUT THE RESULTS
while($productRow=mysql_fetch_array($listProducts))
{
echo $productRow['name'] . "<br />";
echo $productRow['description'] . "<br />";
echo '<a href="#"><img src=" ' . $directory_to_uploads . $productRow['img'] . ' " /></a>';
}
}
It's pretty darn crude but it's one way of storing and retrieving an image.
Re: php, mysql and images ... ARGH!
Posted: Tue Apr 01, 2008 1:02 pm
by nVee
Well with the help of a friend, we managed to rather take the alternative route and put the images directly into the database. Although this is a longer route, we save the effort of likely over-writing some filenames and it loads fast enough ...
Our trouble came in to view the image later, only too find out you have to use a "image replacement file", or a php file with a script to actually view the image, with my little php knowledge, it was a ideal scenario where i had to use the little i know about the php and some common sense and BAM, there the images show and i learnt a great load with this exercise!
Thank you soo much for your help, i think i am falling in love with php, its definately easier than playing the guitar, but i also know i still have ALOT to learn, i just hate reading so darn! But knowledge is power, or atleast money in the bank
speak 2 u soon

Re: php, mysql and images ... ARGH!
Posted: Thu Apr 03, 2008 8:57 pm
by altoyes
aceconcepts wrote:So you need to upload the image to a directory and also store it in the database and then retrieve it also?
Correct?
hi aceconcepts
do you happen to have a complete script which is working?
as i cannot use the snippets of code you have posted thus far,
as it applies to nVee
thankyou for your time.
alto
Re: php, mysql and images ... ARGH!
Posted: Thu Apr 10, 2008 4:13 am
by aceconcepts
What exactly do you need?