$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..."; } } }
<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>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)