<?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); } // if(isset($_POST['save'])){ if(isset($_POST['crud_id'])){ $subjectar= @$_POST['subjects']; $subjectST= implode(',',$subjectar); //echo '<pre>'; print_r($_POST); echo '</pre>'; echo $subjectST; if(isset($_FILES['upload_file'])){ // print_r($_FILES) ; die(); $file_name = $_FILES['upload_file']['name']; $tmpname = $_FILES['upload_file']['tmp_name']; $folder= "upload/".$file_name; move_uploaded_file($tmpname,$folder); if($_POST['crud_id']==''){ $INSQL= "INSERT INTO crud_op (crud_name,crud_gender,crud_subject,crud_country,Crud_img) VALUES('".$_POST['name']."', '".$_POST['gender']."','".$subjectST."','".$_POST['country']."','".$folder."')"; // echo $INSQL; $RUNINSQL= mysqli_query($con,$INSQL) or die('Insert Sql failed'); if($RUNINSQL){ echo '<span> <h2 style="color:green;font-weight:900px;align-items:center;text-align:center">data inseted successfully!!!</h2> </span>'; } }} } //fetch if(@$_GET['uid']!=''){ $fetSQL="SELECT *FROM crud_op WHERE crud_id= '".$_GET['uid']."'"; // echo $fetSQL; $RunFEt= mysqli_query($con,$fetSQL)or die('failed fetch query'); $editData= mysqli_fetch_assoc($RunFEt); $Sb_in_database= $editData['crud_subject']; $changeArray= explode(",",$Sb_in_database); // print_r($changeArray); echo '<pre>'; print_r($editData); echo '</pre>'; } if(@$_POST['crud_id']!=''){ $folder= @$_POST['upload_oldfile']; if($_FILES['upload_file']['name']!=''){ $file_name= $_FILES['upload_file']['name']; $tmpname= $_FILES['upload_file']['tmp_name']; $folder= "upload/".$file_name; move_uploaded_file($tmpname,$folder); $sub= $_POST['subjects']; $changeST= implode(',',$sub); $updateSql= "UPDATE crud_op SET crud_name='".@$_POST['name']."', crud_gender='".@$_POST['gender']."', crud_subject='".@$changeST."',crud_country='".@$_POST['country']."',crud_img='".$folder."' WHERE crud_id='".@$_POST['crud_id']."'"; // echo $updateSql; die(); $Runupdate= mysqli_query($con,$updateSql) or die('failed update query'); if($Runupdate){ echo '<h2 style="color:green;font-weight:900px;align-items:center;text-align:center">data updated successfully!!!</h2>'; } } } //delete if(@$_GET['del']){ $DelSQL = "DELETE FROM crud_op WHERE crud_id= '".$_GET['del']."'"; // echo $DelSQL; $RunDelsql= mysqli_query($con,$DelSQL) or die('del query failed'); if($RunDelsql){ echo '<h2 style="color:red;font-weight:900px;align-items:center;text-align:center">data deleted successfully!!!</h2>'; } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Styled Form</title> </head> <body> <div class="form-container"> <?php if(@$_GET['uid']=='') {echo '<h2>INTER YOUR DATA</h2>';} else{ echo '<h2>UPDATE YOUR DATA</h2>';}?> <form action="<?php $_SERVER['PHP_SELF'] ?>" method="POST" enctype="multipart/form-data"> <div class="form-group"> <input type="hidden" id="name" name="crud_id" value="<?php echo @$_GET['uid']; ?>"> <label for="name" class="form-label">Name:</label><br> <input type="text" id="name" name="name" value="<?php echo @$editData['crud_name'] ?>" class="form-input"> </div> <div class="form-group"> <label class="form-label">Gender:</label><br> <input type="radio" id="male" name="gender" value="male" <?php if("male"==@$editData['crud_gender']) echo 'checked="checked"';?> class="form-radio"> <label for="male" class="form-label">Male</label> <input type="radio" id="female" name="gender" value="female" <?php if("female"==@$editData['crud_gender']) echo 'checked="checked"';?> class="form-radio"> <label for="female" class="form-label">Female</label> </div> <div class="form-group"> <label class="form-label">Subjects:</label><br> <input type="checkbox" id="java" name="subjects[]" value="JAVA" <?php if(@$_GET['uid']!='') {if(in_array("JAVA",$changeArray)) {echo 'checked';}}?> class="form-checkbox"> <label for="java" class="form-label">JAVA</label> <input type="checkbox" id="html" name="subjects[]" value="HTML"<?php if(@$_GET['uid']!=''){ if(in_array("HTML",$changeArray)){echo 'checked';} } ?> class="form-checkbox"> <label for="html" class="form-label">HTML</label> <input type="checkbox" id="css" name="subjects[]" value="CSS" <?php if(@$_GET['uid']!=''){if(in_array("CSS",$changeArray)){echo 'checked';}} ?> class="form-checkbox"> <label for="css" class="form-label">CSS</label> <input type="checkbox" id="php" name="subjects[]" value="PHP" <?php if(@$_GET['uid']!=''){if(in_array("PHP",$changeArray)){echo 'checked';}} ?> class="form-checkbox"> <label for="php" class="form-label">PHP</label> </div> <div class="form-group"> <label class="form-label">Country:</label><br> <select id="country" name="country" class="form-select" > <option value="">Select a country</option> <option value="usa" <?php if('usa'==@$editData['crud_country']) echo 'selected="selected"'?> >USA</option> <option value="uk" <?php if('uk'==@$editData['crud_country'] )echo 'selected="selected"' ?>>UK</option> <option value="canada" <?php if('canada'==@$editData['crud_country']) echo 'selected="selected"';?> >Canada</option> <option value="australia" <?php if('australia'==@$editData['crud_country'])echo 'selected="selected"' ?>>Australia</option> </select> </div> <div class="form-group"> <label for="name" class="form-label">FILE:</label><br> <input type="file" id="name" name="upload_file" value="" class="form-input"> <input type="hidden" id="name" name="upload_oldfile" value="<?php echo @$editData['crud_img'] ?>" class="form-input"> </div> <?php if(@$_GET['uid']==''){ echo '<button type="submit" class="form-submit" name="save">Submit</button>'; } else{echo '<button type="submit" class="form-update" name="edit">UPDATE</button> ';}?> </form> </div><br> <table border="2px;" width="100%"> <tr><td colspan="10" align="center" style="background-color:grey;color:#fff"><h3>YOUR DATA </h3></td></tr> <tr style="background:blue;color:#fff;font-weight:900"> <th> Sr No</th> <th> Name</th> <th> Gender</th> <th> Subject</th> <th> Country</th> <th> img</th> <th> Opertation</th> </tr> <tbody> <?php $disSql="SELECT *FROM crud_op "; $RunSql=mysqli_query($con,$disSql) or die('dis SQL failed'); $abc=1; if(mysqli_fetch_row($RunSql)){ // echo 'ROW FOUND'; foreach($RunSql as $key=>$value){ echo '<tr style="text-align:center;background-color:black;color:#fff"> <td> '.$abc++.'</td> <td> '.$value['crud_name'].'</td> <td> '.$value['crud_gender'].'</td> <td> '.$value['crud_subject'].'</td> <td> '.$value['crud_country'].'</td> <td> <img src="'.$value['crud_img'].'" width="70px" height="70px" </td> <td align:center; valign:middle> <a href="index.php?uid='.$value['crud_id'].'" style="background-color:green;color:#fff;padding:5px;text-decoration:none;margin:1px">EDIT</a> <a href="index.php?del='.$value['crud_id'].'" style="background-color:red;color:#fff;padding:5px;text-decoration:none;margin:1px;">DELETE</a> </td> </tr>'; } } else{ echo '<td colspan="10" align="center" style="background-color:red;color:#fff">NO ROW FOUND</td>'; } ?> </tbody> </table> </body> </html>
May-07-2024 11:13:46
it's very helpful thanks for update!!!!!!!!!!!!
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