Full Post Page
 

INSERT Dropdown Value in mysql Complete CRUD

Category: Latest Source Code & Written by Admin On March-15-2024 15:52:50

<?php $severname="localhost"; $username="root"; $password=""; $dbname="test"; $con=mysqli_connect($severname, $username,$password,$dbname)or die('connection failed'); if(isset($_POST['drop_id'])){ if(@$_POST['drop_id']==''){ $InSql ="INSERT INTO droptable (selectOption) values('".@$_POST['dropOption']."')"; $ExInq= mysqli_query($con,$InSql)or die('insquery failed '); if($ExInq){ echo "data inserted successfully";}}} if(isset($_POST['drop_id'])){ $upSql= "UPDATE droptable SET selectOption='".@$_POST['dropOption']."' WHERE drop_id='".@$_GET['uid']."'"; // echo $upSql; die(); $EXupQ= mysqli_query($con,$upSql) or ('update query failed'); if($EXupQ){ echo 'data updated successfully'; }} if(@$_GET['uid']!=''){ $FetSqID= "SELECT*FROM droptable WHERE drop_id='".@$_GET['uid']."'"; $ExFetq= mysqli_query($con,$FetSqID) or die('failed fetquery'); $editdata= mysqli_fetch_assoc($ExFetq);} if(@$_GET['del']!=''){ $delSql="DELETE FROM droptable WHERE drop_id='".@$_GET['del']."'"; $Exdelq= mysqli_query($con,$delSql) or die('delete query failed'); if($Exdelq){ echo 'data deleted from database'; } }?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Dropdown Form</title> <style> body { font-family: Arial, sans-serif; } .container { max-width: 400px; margin: 50px auto; padding: 20px; border: 1px solid #ccc; border-radius: 5px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } label { display: block; margin-bottom: 10px; font-weight: bold; } select, input[type="text"] { width: 100%; padding: 10px; margin-bottom: 20px; border: 1px solid #ccc; border-radius: 5px; } input[type="submit"] { width: 100%; padding: 10px; background-color: #007bff; color: #fff; border: none; border-radius: 5px; cursor: pointer; transition: background-color 0.3s; } input[type="submit"]:hover { background-color: #0056b3; } table { width: 100%; border-collapse: collapse; } th, td { padding: 12px 15px; text-align: left; border-bottom: 1px solid #ddd; } th { background-color: #f2f2f2; color: #333; font-weight: bold; } tr:hover { background-color: #f5f5f5; } </style> </head> <body> <div class="container"> <h2 style="text-align: center;">INSERT Dropdown Value in mysql</h2> <form action="" method="POST"> <input type="hidden"name="drop_id" value="<?php @$_GET['uid'] ?>"> <label >Select an Option:</label> <select name="dropOption"> <option value="NOSELECT" <?php if('NOSELECT' ==@$editdata['selectOption'])echo 'selected ="selected"'; ?>>NOSELECT</option> <option value="HTML" <?php if("HTML"==@$editdata['selectOption']) echo 'selected="selected"'; ?> >HTML</option> <option value="CSS" <?php if("CSS"==@$editdata['selectOption'])echo 'selected ="selected"'; ?>>CSS</option> <option value="LARAVEL"<?php if("LARAVEL"==@$editdata['selectOption']) echo 'selected ="selected"';?>>LARAVEL</option> <option value="PHP" <?php if("PHP"==@$editdata['selectOption']) echo 'selected="selected"';?>>PHP</option> <option value="JAVASCRIPT" <?php if("JAVASCRIPT"==@$editdata['selectOption']) echo 'selected="selected"';?>>JAVASCRIPT</option> </select> <input type="submit"name="submit"value="Submit"> </form> </div> <h2 style="text-align: center;">Table Example</h2> <table> <thead> <tr> <th>SR</th> <th>CATEGORY</th> <th>OPERATION</th> </tr> </thead> <tbody> <?php $DisSql= "SELECT *FROM droptable"; $ExDq= mysqli_query($con,$DisSql)or die('failed display data'); if(mysqli_num_rows($ExDq)>0){ $abc=1; foreach($ExDq as $key=> $value){ ?> <tr> <td><?php echo $abc++;?></td> <td><?php echo $value['selectOption']?></td> <td><a href="index.php?uid=<?php echo $value['drop_id'] ;?>">UPDATE</a> <a href="index.php?del=<?php echo $value['drop_id']; ?>">DELETE</a></td> </tr><?php }?> <?php }else{echo '<tr align="center"><td colspan="10"> No ROW FOUND!!!</td></tr>';}?> </tbody> </table> </body> </html>

Comments

neha

March-15-2024 18:38:26

Thanks for this!!!


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