Jump to content

Drop Down List


 Share

Go to solution Solved by Barand,

Recommended Posts

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>

 

Untitled.png

Link to comment
Share on other sites

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";
    
    
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.