<?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>
March-15-2024 18:38:26
Thanks for this!!!
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