Full Post Page

Latest Full Posts

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: 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