简体   繁体   English

使用带有输入和提交按钮的while循环在php中回显他们输入的次数

[英]using a while loop with an input and submit button to echo out in php the number of times they enter

I figured out my PHP script using a while loop, now I want to incorporate an input and submit button to have a user pick a date of the month from 1-31 and when they input a date I will have PHP echo out "hello" that many times they entered. 我使用while循环弄清楚了我的PHP脚本,现在我想合并一个输入和提交按钮,以使用户从1月31日选择一个月的日期,当他们输入日期时,我将让PHP回显"hello"他们进入了很多次。

I just cant figure out how to tie it in with an input and submit button so as not to make my code hard coded, I want to make it dynamic. 我只是想不出如何将其与输入和提交按钮绑定在一起,以免使我的代码难以编码,我想使其动态化。

Here is my code: 这是我的代码:

<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
   Enter the date of the month: <input type = "text" name ="Enter the date of the month">
   <input type = "submit" name="submitDate">
</form>

<?php
    $x = 1;
    while($x<=31){
        echo "hello<br>";
        $x++;
    }
?>

your gonna need isset function of php to accept your html user input. 您将需要php的isset函数来接受html用户输入。

HTML HTML

Enter the date of the month: <input type = "text" name ="date">

PHP PHP

    if(isset($_REQUEST['submitDate'])) {
     $x = $_POST['date'];
    }

then you can use $x in your while loop to output hello. 那么您可以在while循环中使用$ x来输出问候。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM