Php 为什么操作后会将代码打印为打印字符串而不是结果?(菲律宾)

Php 为什么操作后会将代码打印为打印字符串而不是结果?(菲律宾),php,output,Php,Output,这是为了学校,所以如果你不想帮助我,我会提前警告你 我在一个html页面中有这段代码,该页面引用了一个名为dieRoller.php的页面: <form method="post" action="dieRoller.php"> <label>Input how many sides your die has:</label> <input type="numberInput" id="numberInput" name="numberInput" /&

这是为了学校,所以如果你不想帮助我,我会提前警告你

我在一个html页面中有这段代码,该页面引用了一个名为dieRoller.php的页面:

<form method="post" action="dieRoller.php">
<label>Input how many sides your die has:</label>
<input type="numberInput" id="numberInput" name="numberInput" /><br />
<input type="submit" value="submit" name="submit" />
</form>

输入模具有多少面:

这是dieRoller.php:

<?php

$numberInput = filter_input(INPUT_POST, "numberInput");
$answerNum = rand(1,numberInput);

print " You've rolled a: " $answerNum;

?>

您有以下错误

您忘记在
rand
函数中为php变量添加
$
符号

更换

$answerNum = rand(1,numberInput);

$answerNum = rand(1,$numberInput);

你犯了以下错误

您忘记在
rand
函数中为php变量添加
$
符号

更换

$answerNum = rand(1,numberInput);

$answerNum = rand(1,$numberInput);

您的压模辊应如下所示:

<?php
if(isset($_POST['numberInput'])){
echo rand(1,$_POST['numberInput']);
}
?>

您的压模辊应如下所示:

<?php
if(isset($_POST['numberInput'])){
echo rand(1,$_POST['numberInput']);
}
?>

下面更正了代码中的两个输入错误,经过测试后,更正的代码仍然有效:


$answerNum = rand(1,$numberInput);

print " You've rolled a: " .$answerNum;

下面更正了代码中的两个输入错误,并且更正后的代码在测试时有效:


$answerNum = rand(1,$numberInput);

print " You've rolled a: " .$answerNum;

这是在安装了php的服务器上吗?它是在测试过的xampp上安装的……你确定其他php文件也在运行吗?PHP是否加载了Apache?另外,
numberInput
不是一个。忘记
$answerNum=rand(1,$numberInput)中的
$
。???@ajp15243-我现在要测试另一个。它昨天起作用了,但我应该先测试一下。这是在安装了php的服务器上吗?它是在测试过的xampp上安装的……你确定其他php文件也在运行吗?PHP是否加载了Apache?另外,
numberInput
不是一个。忘记
$answerNum=rand(1,$numberInput)中的
$
。???@ajp15243-我现在要测试另一个。它昨天起作用了,但我应该先测试一下。谢谢你的演示。我看到了你的评论并修复了它!:)@或者你们现在应该接受答案。谢谢你们的回答。我看到了你的评论并修复了它!:)@或者你们现在应该接受这个答案。当然,这比我的回答要优雅得多。谢谢。那当然比我的要优雅得多。非常感谢。