Jump to content

Drop Down List

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

include "db.php";

$date=Date("Y-m-d H:i:s");






 // 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
        $sq="insert into att(name,date,res)values('$b','$date','$res')";
	echo "Ok";         // 


<!DOCTYPE html>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<link rel="stylesheet" href="">
	<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>

	<input type="text" name="res">
	<input type="submit" name="bt" value="Ok">

<?php echo"". $error;?>



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' ){
    echo "Not Please Select Name Please";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

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.

  • 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.