简体   繁体   English

PHP标记内的HTML表单

[英]HTML form within PHP tags

I want to make a form that submits data from user input into a database. 我想制作一个表单,将用户输入的数据提交到数据库中。 However, when making the form, it does not appear in the browser. 但是,制作表单时,它不会出现在浏览器中。

Here is the code. 这是代码。

echo '<form name="submit" method="post" action="reservation_confirm.php">';
echo '<Confirm: <input type="submit" name="confirm" value="confirm">';
echo '</form>';

You have a less-than sign < to many. 您有一个小于号<对许多人。

Change: 更改:

echo '<Confirm: <input type="submit" name="confirm" value="confirm">';
//----^ remove

To: 至:

echo 'Confirm: <input type="submit" name="confirm" value="confirm">';

It's because of less sign on your second line. 这是因为第二行上的符号较少。 It is considered HTML opening tag. 它被视为HTML开头标记。 Try this: 尝试这个:

echo '<form name="submit" method="post" action="reservation_confirm.php">';
echo '&#60;Confirm: <input type="submit" name="confirm" value="confirm">';
echo '</form>';

Or simply remove it. 或者只是将其删除。

It's not a good practice to put HTML code inside PHP code. 将HTML代码放入PHP代码不是一个好习惯。 What you can do is this: 您可以执行以下操作:

<?php
//Some PHP code here
?>
<h1>Some HTML code here</h1>

This also works: 这也适用:

<?php
if(something) {
?>
    <h1>This is going to be displayed</h1>
<?php
}
?>

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

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