Vikas Vishwakarma
Vikas Vishwakarma

Reputation: 95

how to insert new value in column with same id with old value in mysql

Here with using simple form i am uploading file on server,

<form class="form-inline" action="<?php htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post" role="form" enctype="multipart/form-data">
<input type="hidden"  name="file_id" value="<?php echo $id; ?>">
<input type="file"  name="image" value="choose File" id="choose_file" style="margin-left:-90px;"  multiple>
<input type="submit" value="upload">
</form>

now suppose a table which have id and filename attributes , first time user uploaded the file on server and put the name of file on MySQL column with id '1' and now user want to upload one more file in same MySQL column with same id '1' and previous file should also be there and new one also,Is there any way to do this ? Here is code of uploading file on server

<?php
if(isset($_FILES['image'])){
$errors= array();
$file_name = $_FILES['image']['name'];
$file_size =$_FILES['image']['size'];
$file_tmp =$_FILES['image']['tmp_name'];
$file_type=$_FILES['image']['type'];
$file_ext=strtolower(pathinfo($file_name,PATHINFO_EXTENSION));
$expensions= array("jpeg","jpg","png");
if(in_array($file_ext,$expensions)=== false){
$errors[]="extension not allowed, please choose a JPEG or PNG file.";}  
if($file_size > 2097152){
$errors[]='File size must be less or equal to  2 MB';}
if(file_exists($_FILES['image']['name'])){
$errors[]="file already existed";}
if(empty($errors)==true){
move_uploaded_file($file_tmp,"img/".$file_name);
$error="success";}
else{
print_r($errors);}}
?>

If there is any solution then please answer me . thank you

Upvotes: 1

Views: 110

Answers (1)

Hiram Angeles
Hiram Angeles

Reputation: 46

I think in this case you need to use another value to group the images, for example

Images for a product with id 3 Image 1 Id 1 Name image_1 Product_id 3

Image 2 Id 2 Name image_3 Product_id 3

Image 3 Id 3 Name image_3 Product_id 3

Third row is the same, in this way you can group all the images you want with same id

Hope this helps

Upvotes: 2

Related Questions