Php HTML从选项中选择 [英] Php HTML selecting from option

查看:98
本文介绍了Php HTML从选项中选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试选择选项,当他们选择g1值时会出现错误信息,当你在选项中选择g2或g3值时就没有错误所以我可以将值发送到mysql我真的卡在了这个我不能继续如果有人有一个我可以使用的例子吗?



我尝试了什么:



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:

$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>

推荐答案

错误 = false;

if (isset(


_POST [' btn-submit'])){


_POST['btn-submit']) ) {


问题 = trim(
question = trim(


这篇关于Php HTML从选项中选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆