用PHP操作输入
我正在努力学习一些PHP。我有一个学校作业,如果我有一个输入,该输入必须在PHP中执行一个操作,并且必须打印出一些内容。(我希望你们能理解我的意思:))用PHP操作输入,php,html,Php,Html,我正在努力学习一些PHP。我有一个学校作业,如果我有一个输入,该输入必须在PHP中执行一个操作,并且必须打印出一些内容。(我希望你们能理解我的意思:)) 但这似乎对我不起作用?我错过了什么或做错了什么 提前谢谢 编辑: 输入需要打印出来。所以如果我有一个输入13,它需要显示10。或者,如果我有一个输入2,它需要显示1。试试这段代码 添加isset()检查您的$\u POST['test']设置值与否 并在提交表单后添加以提交表单,其值在php <?php $test = isset($
但这似乎对我不起作用?我错过了什么或做错了什么
提前谢谢
编辑:
输入需要打印出来。所以如果我有一个输入13,它需要显示10。或者,如果我有一个输入2,它需要显示1。试试这段代码
添加isset()
检查您的$\u POST['test']
设置值与否
并在提交表单后添加
以提交表单,其值在php
<?php
$test = isset($_POST[ 'test'])?$_POST[ 'test']:'';
$prijs = 10;
if ($test > 65){
echo $prijs / 2 ;
} else if ($test <= 12){
echo $prijs / 2 ;
} else if ($test < 3){
echo $prijs / 10;
} else if ($test > 12){
echo $prijs;
}
?>
<html>
<form action="" method="post">
<input name="test" id="input" type="text">
<input type="submit" value="submit">
</form>
</html>
Thx Bhargav和pr1nc3,
我混合了你2号发给我的代码,并添加了一些东西。现在它工作正常:)
您必须通过“提交”按钮提交表单,并对同一文件执行操作,如
<?php
if(isset($_POST['submit']) && isset($_POST[ 'test'])){
$test = $_POST[ 'test'];
$prijs = 10;
if ($test > 65){
echo $prijs / 2 ;
} else if ($test <= 12){
echo $prijs / 2 ;
} else if ($test < 3){
echo $prijs / 10;
} else if ($test > 12){
echo $prijs;
}
}
?>
<html>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<input name="test" id="input" type="text" >
<input type="submit" name="submit" value="submit">
</form>
</html>
将对同一文件执行操作,并执行php代码
希望它能帮助你,
谢谢。您想输入什么?不清楚如何提交你的表格
如果你的学校作业是通过谷歌自己完成的,如果我使用像5这样的数字,它不会显示打印出来的。所以输入5需要显示prijs=5或者输入13必须显示prijs=10首先,HTML中没有正文。你应该有一个代码>标记表单和输入的位置。另外,php代码也应该在那里,因为您也将在正文中打印结果,不是吗?Thx我正在添加它
<?php
$test = $_POST[ 'test'];
$prijs = 10;
if ($test > 65){
echo $prijs / 2 ;
} else if ($test <= 12 && $test >=3){
echo $prijs / 2 ;
} else if ($test < 3){
echo $prijs / 10;
} else if ($test > 12){
echo $prijs;
}
<?php
$test = isset($_POST[ 'test'])?$_POST[ 'test']:'';
$prijs = 10;
$a = "Je betaalt ";
$b = " Euro ";
if ($test > 65){
echo $a . $prijs / 2 . $b;
} else if ($test <= 12 && $test >=3){
echo $a . $prijs / 4 . $b;
} else if ($test >= 1 && $test <= 3){
echo $a . $prijs / 10 . $b;
} else if ($test > 12){
echo $a. $prijs . $b;
}
?>
<html>
<body>
<form action="" method="post">
<input name="test" id="input" type="text" placeholder="Hoe oud ben je?">
</form>
</body>
</html>
<?php
if(isset($_POST['submit']) && isset($_POST[ 'test'])){
$test = $_POST[ 'test'];
$prijs = 10;
if ($test > 65){
echo $prijs / 2 ;
} else if ($test <= 12){
echo $prijs / 2 ;
} else if ($test < 3){
echo $prijs / 10;
} else if ($test > 12){
echo $prijs;
}
}
?>
<html>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<input name="test" id="input" type="text" >
<input type="submit" name="submit" value="submit">
</form>
</html>