Php Code for Inserting images in each row
I have need help in the below coding, right now it update the image every time i insert new trough form, i need it should update/insert image in each row not update the same image, kindly help .. code is below
<?PHP
if(isset($_POST['add_value'])){
$sql ="INSERT INTO tb_special_offer (offer_price, offer_title, offer_desc, offer_link) VALUES ('"
.addslashes($_REQUE开发者_高级运维ST['offer_price'])."', '"
.addslashes($_REQUEST['offer_title'])."', '"
.addslashes($_REQUEST['offer_desc'])."', '"
.addslashes($_REQUEST[offer_link])."')";
$qry = mysql_query($sql) or die (mysql_error());
//Image
if($_FILES['offer_img']['name']){
$uploaded_image = $_FILES['offer_img']['name'];
$imgpath = "userfiles/specialoffer/";
if(file_exists($imgpath.$uploaded_image)) unlink($imgpath.$uploaded_image);
if(!move_uploaded_file($_FILES['offer_img']['tmp_name'], $imgpath.$uploaded_image)){
$errMsg= "UPLOAD ERROR..!!!".$_FILES['offer_img']['name'];
}
else {
$sql = "update tb_special_offer set offer_img='$uploaded_image' ";
$qry = mysql_query($sql) or die (mysql_error());
}
}
header("Location: specialoffer?msg=Special Offer Added Successfully!");
exit;
}
?>
Your query means that all rows in your database get that image as value for the offer_img
column. Update means just that: update a row.
If you want to update a specific row, not every row, do something like this:
update tb_special_offer set offer_img='$uploaded_image' where id=xxxx
But I suspect you want to use an INSERT query. As you've not provided any more info I cannot write it for you, but it should be easy. Just read the manual, but it boils down to something like
INSERT into tb_special_offer (offer_img) VALUES ('$uploaded_image')
精彩评论