<?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>
June-06-2025 21:23:08
June-06-2025 11:35:05
June-06-2025 08:25:42
June-02-2025 21:09:41
June-02-2025 10:56:22
June-02-2025 10:27:58
June-02-2025 10:15:40
May-30-2025 19:20:40
May-30-2025 19:14:29
May-27-2025 21:52:18
May-27-2025 21:33:30
May-26-2025 17:11:41
May-26-2025 16:53:29
May-26-2025 16:50:59
May-13-2025 21:02:32
May-13-2025 17:46:23
May-12-2025 15:41:29