Full Post Page

Latest Full Posts

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: Ready to kickstart your coding journey? Subscribe to [Rupesh-Tech] on YouTube and start learning today! Don't forget to hit the bell icon to receive notifications whenever we upload new tutorials or go live with Q&A sessions. Remember, coding opens up a world of endless possibilities. Whether you're dreaming of becoming a software developer, launching your own startup, or simply exploring a new hobby, [Rupesh-Tech] is here to help you turn your coding aspirations into reality. Let's code together and unleash your full potential! Feel free to customize the content to better suit Rupesh-tech channel's branding and audience.



Recent Posts

IMAGE CRUD PHP MYSQL

September-04-2024 09:18:37


complete php project mysql

August-11-2024 11:31:12


LARAVEL 11 crud step by step

August-02-2024 23:22:25