Full Post Page
 

SINGLE PAGE CURD

Category: Latest Source Code & Written by Admin On April-04-2025 12:34:43

<?php error_reporting(0); // ini_set('display_errors', 1); ini_set('log_errors',1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); $con= mysqli_connect("localhost","root","","test") or die("falied connection"); // if($con){ echo "connection done"; } // Check connection if($con === false){ die("ERROR: Could not connect. " . mysqli_connect_error());} // delete if(isset($_GET['del'])){ $delsql= "DELETE FROM `simplecrud` WHERE crud_id='".$_GET["del"]."' "; if(mysqli_query($con,$delsql)){ echo '<script> alert("Records delete successfully")</script>'; }else{ echo die( mysqli_error($con));} } // insert if(isset($_POST['save'])){ // print_r($_POST); if($_GET['uid']==''){ $name=$_POST['name']; // echo $sql="INSERT INTO `simplecrud` ( `crud_name`) VALUES ('mohal')";// echo $sql= "INSERT INTO `simplecrud` (`crud_name`) VALUES ('$name') "; $sql= "INSERT INTO `simplecrud` (`crud_name`) VALUES('".$_POST["name"]."')";// exit(); if(mysqli_query($con, $sql)){ echo "Records inserted successfully.";}} else{ echo die( mysqli_error($con));} } // fetch data if((@$_GET['uid'])){ $fetsql="SELECT *FROM `simplecrud` WHERE crud_id='".$_GET['uid']."'"; $runfet=mysqli_query($con,$fetsql) ; $editData=mysqli_fetch_assoc($runfet); $editData['crud_id']; } // update if(isset($_POST['update'])){ $upsql="UPDATE simplecrud SET crud_name='".$_POST['name']."' WHERE crud_id= '".$_GET['uid']."' "; ; if(mysqli_query($con,$upsql)){ echo "Record successfully updated"; } else{ echo "update failed"; } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Php crud using mysql </title> </head> <body> <div class="heading"> <h1>simple crud</h1> </div> <form action="<?php $_SERVER['PHP_SELF'] ?>" method="POST"> <label for="">name</label><br> <input type="text" hidden="crud_id" id="name" value=""> <input type="text" name="name" id="name" value="<?php echo @$editData['crud_name'] ?>"> <?php if($_GET['uid']==''){echo ' <button type="submit" class="form-submit" name="save">Submit</button>';}else {echo ' <button type="submit" class="form-submit" name="update">update</button>';} ?> </form> <br><br> <!-- display data --> <table border="1" width="50%"> <thead> <tr> <th>Id</th> <th>NAME</th> <th colspan="2">OPERATION</th> </tr> </thead> <tbody> <?php $disql="SELECT *FROM `simplecrud`"; $rundisql=mysqli_query($con,$disql)or die(mysqli_error($con)); if(mysqli_num_rows($rundisql)>0){ // echo 'data found in database'; foreach($rundisql as $key=>$value){ // echo $value['crud_name'].'<br>'; echo '<tr align="center"> <td> '.$value['crud_id'].'</td> <td> '.$value['crud_name'].'</td> <td><a href="index.php?uid='.$value['crud_id'].'">Edit</a> </td><td> <a href="index.php?del='.$value['crud_id'].'">Delete</a></td> <tr>'; } }else{ echo 'data not found in database'; } ?> </tbody> </table> <?php // Close connection mysqli_close($con); ?> </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