Full Post Page

Latest Full Posts

IMAGE INSERT UPDATE DELETE IN DATABASE

Category: Latest Source Code & Written by Admin On April-15-2024 09:35:25

<?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>

Comments

Share your thoughts about this post

Why Choose Us:

Experienced Instructors: Our team of experienced instructors are passionate about coding and dedicated to helping you succeed. With years of industry experience and a knack for teaching, they'll guide you every step of the way. Beginner-Friendly Content: Don't worry if you're new to coding. Our tutorials are designed with beginners in mind, starting from the fundamentals and gradually building up to more advanced topics. Updated Content: Coding is a rapidly evolving field, and we're committed to keeping our content up-to-date with the latest trends, technologies, and best practices. Community Support: Learning to code is more fun and effective when you're part of a supportive community. Join our online community forums to connect with fellow learners, share insights, and collaborate on projects. Get Started Today: Ready to kickstart your coding journey? Subscribe to [Rupesh-Tech] on YouTube and start learning today! Don't forget to hit the bell icon to receive notifications whenever we upload new tutorials or go live with Q&A sessions. Remember, coding opens up a world of endless possibilities. Whether you're dreaming of becoming a software developer, launching your own startup, or simply exploring a new hobby, [Rupesh-Tech] is here to help you turn your coding aspirations into reality. Let's code together and unleash your full potential! Feel free to customize the content to better suit Rupesh-tech channel's branding and audience.



Recent Posts

IMAGE CRUD PHP MYSQL

September-04-2024 09:18:37


complete php project mysql

August-11-2024 11:31:12


LARAVEL 11 crud step by step

August-02-2024 23:22:25