<?php $hostname="localhost"; $username="root";$password="";$database="test"; $con=mysqli_connect($hostname,$username,$password,$database) or die('connection failed'); //delete if(@$_GET['del']!=''){ $DelSql= "DELETE FROM file WHERE file_id='".@$_GET['del']."'"; // echo $DelSql; die(); $RunDel= mysqli_query($con,$DelSql) or die('del sql failed'); if($RunDel){ echo '<div > <h3 style="color:red">data delete successfully</h3> </div>'; }} //insert if(isset($_POST['save'])){ // echo $_POST['user_name']; if($_POST['file_id']==''){ if(isset($_FILES['uploadfile'])){ // print_r($_FILES) ; $file_name = $_FILES['uploadfile'] ['name']; $tempname = $_FILES['uploadfile'] ['tmp_name']; $folder = "upload/" .$file_name; move_uploaded_file($tempname,$folder); // move_uploaded_file($tempname,"upload/. $file_name"); $inSQL= "INSERT INTO file (file_name ,file_img) VALUES ('".$_POST['user_name']."', '".$folder."')"; // echo $inSQL; die(); $RunSql = mysqli_query($con,$inSQL) or die('Insql failed'); if($RunSql){ echo '<div > <h3 style="color:green">data inserted successfully</h3> </div>'; }else{ echo 'data not inserted'; } }} } //fetch if(@$_GET['uid']!=''){ $FetSql= "SELECT *FROM file WHERE file_id='".@$_GET['uid']."'"; // echo $FetSql; $fetQuery=mysqli_query($con,$FetSql) or die ('failed fetquery'); $editData= mysqli_fetch_assoc($fetQuery); // echo '<pre>';// print_r($editData); // echo '</pre>';// die(); } //update if(@$_POST['file_id']!=''){ $folder= @$_POST['upload_old']; if($_FILES['uploadfile']['name']!="") { $file_name = $_FILES['uploadfile'] ['name']; $tempname = $_FILES['uploadfile'] ['tmp_name']; $folder = "upload/" .$file_name; move_uploaded_file($tempname,$folder);} $UPSQL= "UPDATE file SET file_name ='".$_POST['user_name']."', file_img ='".$folder."' WHERE file_id='".$_POST['file_id']."' "; // echo $UPSQL; die(); $RunUPsql=mysqli_query($con,$UPSQL) or die('update sql failed'); if($RunUPsql){ echo '<div > <h3 style="color:yellow">data updated successfully</h3> </div>'; }else{ echo 'data not updated !!!!!!';}}?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> *{margin: 20px;background-color: grey;color: #fff; text-transform:uppercase ; } ?> </style> </head> <body> <h3>UPLOAD FILE IN DATABASE</h3> <form action="<?php $_SERVER["PHP_SELF"] ?>" method="POST" enctype="multipart/form-data"> <input type="hidden" name="file_id" value="<?php echo @$_GET['uid'] ?>"> Name: <input type="text" name="user_name" value="<?php echo @$editData['file_name']?>"> <br> FILE :<input type="file" name="uploadfile"> <br> <input type="hidden" name="upload_old" value="<?php echo $editData['file_img'] ?>"> <input type="submit" value="submit" name="save"> </form> <table width="80%" cellpadding="5px" cellspacing="5px" border="2px"> <thead> <tr style="background-color:black; text-transfrom:uppercase"> <th style="background-color:black">Sr no</th> <th style="background-color:black">Name</th> <th style="background-color:black">Photo</th> <th style="background-color:black">Operation</th></tr> </thead> <tbody> <?php $SelSql= "SELECT *FROM file"; $RunSel=mysqli_query($con,$SelSql) or die('selsql failed'); if(mysqli_fetch_row($RunSel)>0){ // echo 'row found'; $abc=1; foreach($RunSel as $key=>$value){ echo '<tr align="center" valign="middle"> <td>'. $abc++.' </td> <td>'. $value["file_name"] .' </td> <td valign="top"> <img src='.$value["file_img"].' width="180px" height="90px" </td> <td> <a href="file.php?uid='.$value["file_id"].'" style="background-color:green; padding:5px" >UPDATE</a> <a href="file.php?del='.$value["file_id"].'"style="background-color:red; padding:5px" >DELETE</a> </td> </tr>'; } }else{ echo '<td align="center"colspan="10" style="background-color:red"> NO ROW FOUND</td>'; }?> </tbody> </table> </body> </html>
September-04-2024 09:18:37
August-11-2024 11:31:12
August-02-2024 23:22:25
May-12-2024 02:44:34
May-10-2024 20:14:30