Link to home
Start Free TrialLog in
Avatar of darja22
darja22

asked on

Insert image path into db

Hi,
I want to insert images with their paths into my MySQL db and later retrieve them.
But, when tried to execute a query, it says that there was a problem with syntax?  
The "ad_file" column is BLOB.
Here is the code.
$query = "INSERT INTO ad_file SET imageURL = '/public_html/ads/music-468x60.png', '/public_html/ads/music-728x90.png',  '/public_html/ads/smileys-300x250.JPG', '/public_html/ads/smileys-600x160.PNG', '/public_html/ads/smileys1-300x250.PNG'";

Open in new window

Avatar of piotroxp
piotroxp
Flag of Poland image

If you're using mysql then this is the proper query:
[code]
$query = "INSERT INTO ad_file VALUES ( '/public_html/ads/music-468x60.png', '/public_html/ads/music-728x90.png',  '/public_html/ads/smileys-300x250.JPG', '/public_html/ads/smileys-600x160.PNG', '/public_html/ads/smileys1-300x250.PNG'");
[/code]
Provided that ad_file is your table and the fields that you've designed all fit correctly with the data.
Avatar of Fero45
Fero45

Try using table_name and WHERE clause, e.g.

INSERT INTO myTable ... WHERE id='12345'

You do not INSERT INTO a column, you INSERT INTO a table.
Plus you have to close the parentheses at the end, sorry my mistake.
Error i because you have the ad_file column set as a blob type. This is used when you want to store a binary file ie image etc, in the database.

You do not seem to want to do this a you seem to be just storing the path to the image. If this is the case, edit your database and change the ad_file column from BLOB to another type that handles text.

If you do wish to store the whole image in the column as binary data then you will need to change your code.

Let me know which you want to do and I can provide more detail if needed.
Ignore my above reply. I read question wrong and read an error message which wan't there :-s

sorry
Avatar of darja22

ASKER

Thanks for the answers:)
Well, I really do not want to store the image, but only the path to it, so I guess I have to change the ad_file to VARCHAR, right?
The whole thing is intended for banner display, in which the code would be combined like this:
<?php 
<!--DB connection query-->
?>
 
<a href="http://ads.domain.com/click.php?id=' + productID + adID + '<?=$_GET["affID"]; ?>&amp;c=n" target="_blank" ><img src="http://ads.domain.com/image.php?id=' + productID + adID + '<?=$_POST["affID"]; ?>" width="720" height="300" border="0" alt=""></a>');

Open in new window

Avatar of darja22

ASKER

Thx, Piotroxp:)
Almost, but...
I have misstyped - not the ad_file (which is a column), but "ads", which is a table. I tried, but again, the syntax error, altough I have closed the parentheses at the end:(
Help a little more,pls?
Avatar of theGhost_k8
a code snip:
To insert:-

$instr = fopen("latest.img","rb");
$image = addslashes(fread(fopen("latest.img","r"),filesize("latest.img")));
mysql_query ("insert into pix (pic_name, pic_data) values ('".$ImageName."', '".$image."');");

To retrieve:-
            $res = @mysql_query("select * from pix order by pic_id desc limit 1");
            $title = htmlspecialchars($row[pic_name]);
            $bytes = $row[pic_data];
            header("Content-type: image/jpg");
            print $bytes;
ASKER CERTIFIED SOLUTION
Avatar of SerjTech
SerjTech

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of darja22

ASKER

Thanks for all the help:)