【问题标题】:PHP form with function argument带有函数参数的 PHP 表单
【发布时间】:2014-03-12 21:33:23
【问题描述】:

我有这个 php 代码:

<?php
        echo '<form action="index.php" method="post">
                <h3>ggjnjskrngjekrng</h3>
                <p>
                    <input type="text" name="nbmatchs" />
                    <input type="submit" value="ok" />
                </p>
                </form>';
        echo getLastMatchs($nbmatchs);
        ?>

我的功能:

function getLastMatchs(int $nb) {
    $i=0;
    while ($nb < $i )
    {
    return 'hello';
    $i++;
    }
}

例如,如果 nbmatchs 为 5,我想返回,返回 5x“Hello”。 我该怎么办?

我有这个错误:

Notice: Undefined variable: nbmatchs in C:\...

Catchable fatal error: Argument 1 passed to getLastMatchs() must be an instance of int, null given, called in C:\.. and defined in C:\...

【问题讨论】:

  • 来自 php.net:类型提示不能用于标量类型,例如 int 或 string。也不允许使用资源和特征。

标签: php forms function return


【解决方案1】:

似乎有点无意义,但是:

echo getLastMatchs($_POST['nbmatchs']);

function getLastMatchs($nb) {
    return str_repeat('hello', (int)$nb);
}

【讨论】:

  • 确实(几乎)所有东西都有本机功能:D
  • 谢谢,工作,但我想要 sql 结果,我只需要广告 sql 行或更改其他东西?
  • @flavien317:我不知道你想要什么。您的问题与 SQL 无关。开始另一个问题并解释 SQL 问题。
猜你喜欢
  • 1970-01-01
  • 2012-04-18
  • 2011-04-28
  • 1970-01-01
  • 2015-04-26
  • 1970-01-01
  • 1970-01-01
  • 2012-12-03
  • 1970-01-01
相关资源
最近更新 更多