PHP代码不起作用?

时间:2014-07-31 23:17:18

标签: php html

我更新,并从youtube教程学习PHP。但是在教程中,同样的PHP代码工作没有任何错误,而在我的系统上,它显示的是图片中显示的内容。请帮忙!!

<?php
if(isset($_POST['user_input'])&&!empty($_POST['user_input']))
{
    $string = $_POST['user_input'];
    echo $string;
}
?>
<hr>
<form action="index.php" method="POST">
    <textarea name="user_input" rows="10" cols="30"><?php echo $user_input; ?></textarea>
    <br /><br />
    <input type="submit" value="Submit" />
</form>

输出:

enter image description here

2 个答案:

答案 0 :(得分:3)

您在此处呼叫时未曾定义$user_input<?php echo $user_input; ?>

我相信你想要这个作为你的代码:

<?php
if(isset($_POST['user_input'])&&!empty($_POST['user_input']))
{
    $string = $_POST['user_input'];
    echo $string;
}
?>
<hr>
<form action="index.php" method="POST">
    <textarea name="user_input" rows="10" cols="30"><?php if(isset($string)) echo $string; ?></textarea>
    <br /><br />
    <input type="submit" value="Submit" />
</form>

答案 1 :(得分:0)

只需更改textarea标记中的名副其实的名称,因为您没有定义$user_input;并在ifset中放置条件

  

echo $ user_input;

  

echo($ string)?'$ string':'';