PHP表单限制来自html帖子的一些值

时间:2016-04-29 10:52:05

标签: php

我的HTML代码:

{% extends "base.html" %}

{% block title %}Index{% endblock %}
{% block head %}
    {{ parent() }}
    <style type="text/css">
        .important { color: #336699; }
    </style>
{% endblock %}
{% block content %}
    <h1>Index</h1>
    <p class="important">
        Welcome on my awesome homepage.
    </p>
{% endblock %}

这是我的PHP代码:

<form action="myfile.php" method="POST">
 Data
 <select id="data" name="data" class="form-control" required>
                          <option value="data1">Data 1</option>
                          <option value="data2">Data 2</option>
                        </select>

Value
 <select id="value" name="value" class="form-control" required>
                          <option value="1">1</option>
                          <option value="2">2</option>
                              <option value="3">3</option>
                          <option value="4">4</option>
                        </select>
</form>

如果选择数据1并且值必须大于3,如果不是,它将会注意到“数据1的值必须大于3”,如果没有错误,它将返回到我的进程

2 个答案:

答案 0 :(得分:0)

检查:

$nr =0;
while($row = $result->fetch_assoc() ) {
         $nr++;
         if(($count-1)%3==0) echo '<div class="row">';
         //Add your content units here.
         if(($count)%3==0) echo '</div>';
}

答案 1 :(得分:0)

试试这个

if($data == "data1" && $value > 3) {
   //everything is fine
} else {
   // through notice
}