PHP推出HTML,更好的方式?
基本上这就是我所拥有的:PHP推出HTML,更好的方式?,php,html,Php,Html,基本上这就是我所拥有的: <form method="POST" action="model.php"> <input type="hidden" name="from" value="edit"> <?php include 'model.php'; $c
<form method="POST" action="model.php">
<input type="hidden" name="from" value="edit">
<?php
include 'model.php';
$contactID = $_POST['editConRad'];
selectSingle($contactID);
echo "<input type='hidden' name='contactID' value='$contactID'>";
echo "<label>First Name:</label>";
echo "<input type="text" name="fname">";
echo "<label>Last Name:</label>";
echo "<input type="text" name="lname">";
echo "<label>Email:</label>";
echo "<input type="email" name="email">";
echo "<label>Street Address:</label>";
echo "<input type="text" name="streetaddress">";
echo "<label>City:</label>";
echo "<input type="text" name="city">";
echo "<label>Province:</label>";
echo "<input type="text" name="province">";
echo "<label>Postal Code:</label>";
echo "<input type="text" name="postalcode">";
echo "<label>Phone:</label>";
echo "<input type="number" name="phone">";
echo "<label>Date of Birth:</label>";
echo "<input type="date" name="yob">";
echo "<input type="submit" value="Submit Edit">";
?>
</form>
只要添加适当的标记,就可以随时在PHP和HTML之间切换
例如:
<?php
echo "This is output from an echo statement<br>"
?>
This is plain old HTML<br>
<?php
echo "And now we're back to PHP<br>"
这是普通的旧HTML
我本以为这是回声
会导致错误吗?您可以关闭PHP标记,然后简单地创建HTML。HTML和PHP在脚本中是可以互换的。为什么不脱离PHP呢<代码>?>第二个示例中的所有HTML都没有像您预期的那样进行连接。您可以删除
s,因为它们将按原样输出。非主题:请注意在将$\u POST($\u POST['editConRad']
)放入字段之前对其进行清理,以避免XSS和其他安全问题。
<?php
echo "This is output from an echo statement<br>"
?>
This is plain old HTML<br>
<?php
echo "And now we're back to PHP<br>"
<form method="POST" action="model.php">
<input type="hidden" name="from" value="edit">
<?php
// Do this bit in PHP
include 'model.php';
$contactID = $_POST['editConRad'];
selectSingle($contactID);
?>
<!-- Now switch back to HTML -->
<!-- PHP variable embedded here-------------|................| -->
<input type='hidden' name='contactID' value='<?= $contactID?>'>";
<label>First Name:</label>
<input type="text" name="fname">
<label>Last Name:</label>";
<input type="text" name="lname">
<label>Email:</label>
<input type="email" name="email">
<!-- and so on -->
</form>
<?php
// You can store long text strings in HEREDOC or NOWDOC syntax
$longString = <<<'EOT'
This is an arbitrarily long string, but this one is only short<br>
EOT
echo $longString;