Full Post Page
 

INSERT UPDATE DELETE MULTIPLE CHECKBOX

Category: Latest Source Code & Written by Admin On March-14-2024 18:16:48

@@@@@@@@ CREARE FILE INDEX.PHP@@@@@@@@ <?php $hostname= "localhost";$username= "root";$password= "";$database= "test"; $con= mysqli_connect($hostname,$username,$password,$database) or die("couldn't connect to database"); //del if($_GET['del_id']!=''){ $delSql="DELETE FROM mtype WHERE mtype_id='".@$_GET['del_id']."'"; $delQuery=mysqli_query($con,$delSql) or die('del query failed'); if($delQuery){ echo "data deleted successfully"; }}?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>insert multiple checkbox</title> <link rel="stylesheet" href="css/bootstrap.min.css" type="text/css"> <link rel="stylesheet" href="css/bootstrap.css" type="text/css"> <link rel="stylesheet" href="style.css" type="text/css"></head><body> <form action="index.php" method="post"> <fieldset><div><input type="hidden" name="mtype_id" value="<?php @$_GET['uid']?> > </div> <label>Favorite Pet?</label> <input type="checkbox" name="interest[]" value="Cats" ><label style="margin-left: 5px;" for="">Cats</label> <input type="checkbox" name="interest[]" value="Cats" ><label style="margin-left: 5px;" for="">Cats</label> <input type="checkbox" name="interest[]" value="RAT" ><label style="margin-left: 5px;" for="">RAT</label> <input type="checkbox" name="interest[]" value="Dogs" ><label style="margin-left: 5px;" for="">Dogs</label> <input type="checkbox" name="interest[]" value="Birds" ><label style="margin-left: 5px;" for="">Birds</label> <input type="checkbox" name="interest[]" value="lie" ><label style="margin-left: 5px;" for="">lie</label> </fieldset> <br> <input type="submit" name="submit" value="Submit"> </form></body></html><?php if(isset($_POST['mtype_id'])){ $ar=$_POST['interest']; // echo $ar; die(); $Chst = implode("," ,$ar); $SQL= "insert into mtype(interest) values('$Chst')"; $Query =mysqli_query($con,$SQL) or die('query failed insert'); if($Query){ echo '<div style"text-align:center; font-weight:900;font-size:32px"> data inserted successfully</div>';}} //data display $disSQL="select *from mtype "; $dQuery=mysqli_query($con,$disSQL) or die('dis quer falied'); ?><table width="100%"> <thead><tr> <th style="text-align: center;">#</th> <th style="text-align: center;"></>ID</th> <th style="text-align: center;"></>CHECHBOX</th> <th style="text-align: center;"></>operation</th> </tr></thead><tbody> <?php $abe=1; foreach($dQuery as $key=>$value){ ?><tr> <td style="text-align: center;"><?php echo $abc++ ;?></td> <td style="text-align: center;"><?php echo $value['mtype_id']?></td> <td style="text-align: center;"><?php echo $value['interest'] ?></td> <td style="text-align: center;"> <a href="update.php?uid=<?php echo $value['mtype_id'] ?>" style="background: green;padding: 5px;color: white;"<input type='submit' value='Update' class='update'> update</a> <a href="index.php?del_id=<?php echo $value['mtype_id'] ?>" style="padding=5px; font-size:20px ;background:red; color:white font_weight:900">delete</a></td> </tr><?php } ?></tbody></table> @@@@@@@@ CREARE FILE UPDATE.PHP@@@@@@@@ <?php $hostname= "localhost";$username= "root";$password= "";$database= "test"; $con= mysqli_connect($hostname,$username,$password,$database) or die("couldn't connect to database"); //fetch if(@$_GET['uid']!=''){ // echo $_GET['uid']; die(); $fetSql = "select *from mtype where mtype_id='".@$_GET['uid']."'"; $fetQuery=mysqli_query($con,$fetSql) or die ('failed fetquery'); $editData=mysqli_fetch_assoc($fetQuery); $ST=$editData['interest']; $AR=explode(',',$ST); }?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>insert multiple checkbox</title> <link rel="stylesheet" href="css/bootstrap.min.css" type="text/css"> <link rel="stylesheet" href="css/bootstrap.css" type="text/css"> <link rel="stylesheet" href="style.css" type="text/css"></head> <body><form action='' method="post"><fieldset> <input type="checkbox" name="interest[]" value="Cats" <?php if(in_array('Cats', $AR)) {echo "checked";}?> ><label style="margin-left: 5px;" for="">Cats</label> <input type="checkbox" name="interest[]" value="RAT" <?php if(in_array('RAT', $AR)) {echo "checked";}?> ><label style="margin-left: 5px;" for="">RAT</label> <input type="checkbox" name="interest[]" value="Dogs" <?php if(in_array('Dogs', $AR)) {echo "checked";}?> ><label style="margin-left: 5px;" for="">Dogs</label> <input type="checkbox" name="interest[]" value="Birds"<?php if(in_array('Birds',$AR)) {echo "checked";}?> ><label style="margin-left: 5px;" for="">Birds</label> <input type="checkbox" name="interest[]" value="lie" <?php if(in_array('lie', $AR)) {echo "checked";}?> ><label style="margin-left: 5px;" for="">lie</label> <div class="text-left"> <br> <input type="hidden" value="<?php echo $_GET['uid'] ?>" name="mtype_id"> <!-- <input type="submit" value="update" class="btn" name="edit"> --> <input type="submit" name="edit" value="update"></div> </div></fieldset></form></body></html><?php // update // if(@$_POST['mtype_id']!=''){ if(isset($_POST['edit'])){ $id=$_GET['uid']; // echo $_GET['uid']; die(); $mtype_id = mysqli_real_escape_string($con, $_GET["mtype_id"]); $Ar = $_POST['interest']; $D = implode(", ",$Ar); $UPSql ="UPDATE mtype SET interest='$D' WHERE mtype_id='$id' "; // echo $UPSql; exit(); $UPQuery = mysqli_query($con,$UPSql) or die('update query failed'); if($UPQuery){ echo 'data updated successfully!!!!!!!!!!!!'; }else{ echo 'data not updated'.mysqli_connect_error();}}?>

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