samowns Posted May 4, 2022 Share Posted May 4, 2022 Hello Guys My code runs fine but value null is inserting if some one dint select any list name . So wot i want if some one did not select any option query did not run $error shows Here is my code please check and figure it out <?php $error=""; include "db.php"; if(isset($_POST['bt'])){ $date=Date("Y-m-d H:i:s"); $b=$_POST['name']; $res=$_POST['res']; if(!$_POST["res"]){ } if(!$_POST["name"]){ } // Declare variable if(!$_POST["name"] or ["name"] == '' ) { $error .= "Must select the name.<br />";// If not selected, add string to error message } if(!$_POST["res"] ){ $error .= "Must Enter the Reason.<br />"; // If not Enter, add string to error message } else{ $sq="insert into att(name,date,res)values('$b','$date','$res')"; $sq1=mysqli_query($a,$sq); echo "Ok"; // } } ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title></title> <link rel="stylesheet" href=""> </head> <body> <form action="pres.php" method="post" accept-charset="utf-8"> <select name="name" > <option value="" >Choose...</option> <option value="mandeep" >Maneep</option> <option value="sahiba" >Sahiba</option> </select> </select> <input type="text" name="res"> <input type="submit" name="bt" value="Ok"> <br> <?php echo"". $error;?> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/314759-drop-down-list/ Share on other sites More sharing options...
Solution Barand Posted May 4, 2022 Solution Share Posted May 4, 2022 The only condition you have for not inserting is if the reason has an error. You should prevent insertion if there are any errors. Quote Link to comment https://forums.phpfreaks.com/topic/314759-drop-down-list/#findComment-1595927 Share on other sites More sharing options...
samowns Posted May 4, 2022 Author Share Posted May 4, 2022 Please Tell me how am new to php Quote Link to comment https://forums.phpfreaks.com/topic/314759-drop-down-list/#findComment-1595928 Share on other sites More sharing options...
samowns Posted May 4, 2022 Author Share Posted May 4, 2022 24 minutes ago, Barand said: The only condition you have for not inserting is if the reason has an error. You should prevent insertion if there are any errors. i figure out Thanx elseif (!$_POST["name"] or ["name"] == '0' ){ $sq1=mysqli_query($a,$sq); echo "Not Please Select Name Please"; } Quote Link to comment https://forums.phpfreaks.com/topic/314759-drop-down-list/#findComment-1595930 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.