如何在显示记录之前验证表单输入 [英] How do i verify form input before displaying record

查看:64
本文介绍了如何在显示记录之前验证表单输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在实现中具有以下代码,我想在输出我尝试过的$ text记录之前,先验证是否在表格中插入了1234:

I have this code below in achievement i want to verify if 1234 is inserted in form before output the record in $text i have tried:

 $text = "12345678910111213141516171819202121";

 $pas = "1234";

 if(isset($_POST["subscribe"]))

 {

 $phone = $_POST["phone"];

 if($phone = "$pas")
 {

 echo $text;

 }
if($phone != "$pass")
 {

 echo erro;

 }

 }

     echo '<form action="#" method="POST">
Your Phone Number <br> <input type="text" name="phone" value="080"/><input type="submit" name="subscribe" value="SEND PAYMENT"/></form></div>';

但是当在表单中提交空或错误的$ pas时,我会在$ text中得到记录。
提前谢谢

but i get record in $text when empty or wrong $pas is submited in the form. Great thanks in advance

推荐答案

这是因为 = 是赋值运算符, == 是相等比较运算符。因此,请尝试以下操作:

This is because = is assignment operator and == is equality comparison operator. So try the following instead:

 if($phone == $pas)
 {

    echo $text;

 }

编辑:评论中的问题。输出 html 时应避免 echo ,因此,请尝试以下代码隐藏 submit 按钮,当 $ phone 匹配时。像这样:

Answer to the question in the comment. You should avoid echo when outputing html, So try the following code to hide the submit button when $phone matches. Like:

<?php 
$text = "12345678910111213141516171819202121";
$pas = "1234";

if (isset($_POST["subscribe"]))
{
    $phone = $_POST["phone"];
    if ($phone == $pas)
    {
        echo $text;
    }

    if ($phone != "$pass")
    {
        echo erro;
    }
}

?>
<form action="#" method="POST">
    Your Phone Number <br /> 
    <input type="text" name="phone" value="080"/>
    <?php if(isset($_POST["phone"]) || $_POST["phone"] != $pas): ?>
        <input type="submit" name="subscribe" value="SEND PAYMENT"/>
    <?php endif; ?>
</form>

这篇关于如何在显示记录之前验证表单输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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