Click here to Skip to main content
16,017,881 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to do select Option when they select g1 value it has an error message and when you select g2 or g3 value in option there will be no error so i can send the value to mysql I'am really stuck in this one I can't continue If someone has an example I can use?

What I have tried:

PHP
$error = false;

           if ( isset($_POST['btn-submit']) ) {


                  $question = trim($_POST['gender']);
                  $question = strip_tags($gender);
                  $question = htmlspecialchars($gender);

        // basic gender validation
         if (empty($question)) {
        $error = true;
    $questionError = "Please Select a Question!";
           }


    // if there's no error, continue to submit
    if( !$error ) {

        $query = "INSERT INTO questions(question1, question2) VALUES('$q1','$q2')";
        $res = mysql_query($query);

        if ($res) {
            $errTyp = "success";
            $errMSG = "Successfully created";
            unset($question);
        } else {
            $errTyp = "danger";
            $errMSG = "Something went wrong, try again later...";
        }

    }


}



HTML
<form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" autocomplete="off">
            <?php
			if ( isset($errMSG) ) {
				
				?>
				<div class="form-group">
            	<div class="alert alert-<?php echo ($errTyp=="success") ? "success" : $errTyp; ?>">
				<span class="glyphicon glyphicon-info-sign"></span> <?php echo $errMSG; ?>
                </div>
            	</div>
                <?php
			}
			?>
			<!-- Question Form Group-->			
			<div class="form-group col-md-2">
			<label>Question 1</label>
               <div class="input-group">
			   <span class="input-group-addon"></span>
                      <select name="question" class="form-control" placeholder="Choose Question" value="<?php echo $question ?>" />

		      <option value="g1">~~~Select Question~~~</option>
                      <option value="g2">What is the value of 33?</option>
                      <option value="g3">Who is the best professor?</option>
                      <option value="g4">How many is this?</option>
                      <option value="g5">99 x 50?</option>
                      <option value="g6">1000 - 7?</option>
                   </select>
				   </div>
				   <span class="text-danger"><?php echo $questionError; ?></span>
                 </div>
				 
		</div>		

		<div class="form-group col-md-3">
            	<button type="submit" class="btn btn-block btn-success" name="btn-submit">Submit</button>
            </div>
</form>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900