Full Post Page
 

OOP CRUD PHP MYSQLI INSERT UPDATE DELETE DIFFERNERT INPUT

Category: Latest Source Code & Written by Admin On April-04-2024 08:20:55

<?php $servername ="localhost";$username ="root";$password ="";$dbname ="test"; $con= new mysqli($servername,$username,$password,$dbname); if($con->connect_error){ die("connection failed:" .$con->connect_error); } // echo '<pre>'; print_r($_POST);echo '</pre>'; //insert if(isset($_POST['save'])){ if($_POST['contacts_id']==''){ // if(isset($_FILES['upload_file'])){ $filename = @$_FILES['upload_file']['name']; $temname = @$_FILES['upload_file']['tmp_name']; $folder = "upload/" .$filename; move_uploaded_file($temname,$folder); // echo '<pre>'; print_r($_POST); echo '</pre>'; $insQuery = "INSERT INTO contacts (contacts_name,contacts_gender,contacts_subject,contacts_img,contacts_message) values('".@$_POST['name']."' ,'".@$_POST['gender']."','".@$_POST['subject']."','".$folder."','".@$_POST['message']."')"; $runQuery= $con->query($insQuery); if($runQuery){ echo "<h2>Data Inserted Successfully.</h2>"; }else{ echo "<h2>Data is Not Inserted Successfully.</h2>"; }}} //update if(@$_GET['uid']!=''){ $fetchSQL= "SELECT *FROM contacts where contacts_id='".$_GET['uid']."'"; $Runfet= $con->query($fetchSQL); $editdata= $Runfet->fetch_assoc(); } // if(isset($_POST['save'])){ if(@$_POST['contacts_id']!=''){ $folder= @$_POST['upload_old_file']; if($_FILES['upload_file']['name']!=''){ $filename= $_FILES['upload_file']['name']; $temname= $_FILES['upload_file']['tmp_name']; $folder= "upload/".$filename; move_uploaded_file($folder,@$tmp_name) ; } $updateSQL= "UPDATE contacts SET contacts_name='".$_POST['name']."' ,contacts_gender='".$_POST['gender']."' , contacts_subject='".$_POST['subject']."' , contacts_img='".$folder."' , contacts_message='".$_POST['message']."' WHERE contacts_id='".@$_POST['contacts_id']."'"; $RunUpdate= $con->query($updateSQL);} //delete if(@$_GET['del']!=''){ $delSQL="DELETE FROM contacts where contacts_id='".@$_GET['del']."'"; // $runDEl= mysqli_query($con,$delSQL); $runDEl= $con->query($delSQL); }?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Contact Form</title> </head> <body> <h2>Contact Form</h2> <form action="" method="POST" enctype="multipart/form-data"> <label for="name">Name:</label><br> <input type="hidden" id="name" name="contacts_id" value="<?php echo @$_GET['uid'] ?>"> <input type="text" id="name" name="name"value="<?php echo @$editdata['contacts_name']?>" required> <br><br> <label for="gender">Gender:</label><br> <input type="radio" id="male" name="gender" value="male" <?php if("male"==@$editdata['contacts_gender'] ) echo 'checked ="checked"'; ?> accept="" required> <label for="male">Male</label> <input type="radio" id="female" name="gender" value="female" <?php if("female"==@$editdata['contacts_gender']) echo 'checked="checked"'; ?>> <label for="female">Female</label><br><br> <label for="subject">Subject:</label><br> <select id="subject" name="subject" required> <option value="Select" <?php if("Select"==@$editdata['contacts_subject']) echo 'selected="selected"'; ?>>Select a subject</option> <option value="java" <?php if("java"==@$editdata['contacts_subject'])echo 'selected="selected"';?> > Java</option> <option value="html" <?php if("html"==@$editdata['contacts_subject'])echo 'selected="selected"';?>> HTML</option> <option value="css" <?php if("css"==@$editdata['contacts_subject']) echo 'selected="selected"';?>> CSS</option> <option value="php" <?php if("php"==@$editdata['contacts_subject'])echo 'selected="selected"';?>> PHP</option> </select><br><br> <label for="image">Image:</label><br> <input type="file" id="image" name="upload_file"><br><br> <input type="hidden" id="image" name="upload_old_file" value="<?php echo @$editdata['contacts_img'] ?>"> <?php if(@$editdata['contacts_img']!='')echo '<img src= "'.$editdata['contacts_img'].'"width="50px" <a href="'.$editdata['contacts_img'].'" target="_blank"> </a> ' ?> <label for="message">Message:</label><br> <textarea id="message" name="message" rows="4" required> <?php echo @$editdata['contacts_message'] ?> </textarea><br><br> <input type="submit" name="save" value="Submit"> </form> <table width="100%" cellpadding="12px" cellspacing="2px"> <thead> <tr> <th>#</th> <th>NAME</th> <th>PHOTO</th> <th>GENDER</th> <th>SUBJECT</th> <th>MESSGSGE</th> <th>OPERAATION</th> </tr> </thead> <tbody> <?php $Displaysql= "SELECT *FROM contacts"; $rundsql= $con->query($Displaysql); // print_r($rundsql); exit(); if($rundsql->num_rows >0){ $abc= 1; // while($row= $result->fetch_assoc()){ // while($row=mysqli_fetch_assoc($rundsql)){ foreach($rundsql as $key=>$value){ echo '<tr align="center"> <td> '.$abc++.';</td> <td> '.$value["contacts_name"].';</td> <td>'.$value["contacts_gender"].'</td> <td>'.$value["contacts_subject"].'</td> <td> <img src='.$value["contacts_img"].' width="50px" height="50px"</td> <td> '.$value["contacts_message"].'</td> <td> <a href="index1.php?uid='.$value["contacts_id"].'">Edit</a> <a href="index1.php?del='.$value["contacts_id"].'" >DELETE</a> </td> </tr>'; } }else{echo '<tr><td colspan="12"> NO ROW FOUND</td></tr>';} ?> </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:



Recent Posts

Advance Js Fetch API Part-5

June-06-2025 21:23:08


Advance Js Promise Part-4

June-06-2025 11:35:05


Advance js oop part-3

June-06-2025 08:25:42


ExpressJs API With Image Crud-3

June-02-2025 21:09:41


NodeJs API-MVC-2

June-02-2025 10:56:22


ExpressJs API Crud-1

June-02-2025 10:27:58


ExpressJs Files upload

June-02-2025 10:15:40


NodeJS Cookie and CsrfToken

May-30-2025 19:20:40


ExpressJS Session

May-30-2025 19:14:29


ExpressJS NodeJs Crud Part-2

May-27-2025 21:52:18


ExpressJS NodeJS Crud Part-1

May-27-2025 21:33:30


ExpressJS Authentication

May-26-2025 17:11:41


NodeJS ExpressJS Files Upload

May-26-2025 16:53:29



Angular Introduction

May-13-2025 21:02:32



Advance Js part-1

May-12-2025 15:41:29