Changing image name in XAMPP database by using PHP -


i have form user upload image , write id, want image automatically rename id wrote in form.the current code able rename image according id in folder desired id, however, need image name change desired id in database too, image name in database still original name.

<?php     $servername="localhost";     $username="root";     $password="";     $db = mysqli_connect($servername,$username,$password,"ecom_product"); $msg = ""; //if upload button pressed if(isset($_post['upload']))      {     // path store uploaded image     //$destination_path = getcwd().directory_separator; $item_code = $_post['code']; $filename = $_files["image"]["name"]; $source = $_files["image"]["tmp_name"]; $path_parts = pathinfo($_files["image"]["name"]); $extension = $path_parts['extension']; $destination = "img/$item_code." . $extension; move_uploaded_file($source, $destination);         // submitted data form     $item_code = $_post['code'];     $cat_name = $_post['category'];     $item_name = $_post['item_name'];     $image = $_files['image']['name'];     $text = $_post['text'];     $price = $_post['price'];      $sql = "insert ecom_item (item_code, cat_name, item_name, image, text, price) values ('$item_code','$cat_name','$item_name','$image','$text','$price')";     mysqli_query($db,$sql); // stores submitted data database table : item      if(!is_dir("img/"))     {         mkdir("img/");     }      // move uploaded image folder : img    }  ?>  <!doctype html> <html> <head> <title>image upload description</title> <!--<link rel="stylesheet" type="text/css" href="formstyle.css">--> </head> <body> <?php     $servername="localhost";     $username="root";     $password="";     $db = mysqli_connect($servername,$username,$password,"ecom_product");     $sql = "select * ecom_item order item_code asc";     $result = mysqli_query($db, $sql); ?>       <center>     <form name='show_item' action="exampleadditem.php" method='post' align="center" enctype="multipart/form-data">     <h2 align="center">view item</h2>     <td><input type="submit" name="upload" value="add new item" action="exampleadditem.php" style="width: 98px; height: 36px" size="18"><td>     <br/><br/>     <table border=1  align="center" width="900">     <tr>         <th>item code<th>category<th>item name<th>image<th>description<th>price (rm)<th>actions</th>     </tr>     <?php         while ($row = mysqli_fetch_array($result))         {             echo "<tr>";             echo "<div id='img_div'>";                 echo "<td width='60'>".$row['item_code']."</td>";                 echo "<td width='80'>".$row['cat_name']."</td>";                 echo "<td width='80'>".$row['item_name']."</td>";                 echo "<td width='65'><img src='img/".$row['image']."'width=30 height=30></td>";                 echo "<td width='250'>".$row['text']."</td>";                 echo "<td width='25'>".$row['price']."</td>";                 echo"<td width='90'><a href='editform.php?item_code=".$row['item_code']."'>edit</a> |                  <a href='delete.php?item_code=".$row['item_code']."'>delete</a></td>";             echo "</div>";             echo "</tr>";         }     ?>      </table>     </center>     </form> </body> </html> 

edit: image name did change item code in img folder in database remains original name.

database table image


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -