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.
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'";
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.
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.
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
sorry
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:
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"]; ?>&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>');
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?
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?
a code snip:
To insert:-
$instr = fopen("latest.img","rb");
$image = addslashes(fread(fopen("la test.img", "r"),files ize("lates t.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;
To insert:-
$instr = fopen("latest.img","rb");
$image = addslashes(fread(fopen("la
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_
$bytes = $row[pic_data];
header("Content-type: image/jpg");
print $bytes;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for all the help:)
[code]
$query = "INSERT INTO ad_file VALUES ( '/public_html/ads/music-46
[/code]
Provided that ad_file is your table and the fields that you've designed all fit correctly with the data.