PHP语法中的HTML

时间:2017-06-13 06:36:41

标签: php html syntax

我正在尝试使用PHP和HTML显示基于逻辑语句的提交按钮,但我无法弄清楚语法。

if(isset($_POST['newSubmit'])){ 
    <input type="submit" name="newSubmit" id="newSubmit" value="Select" />;    
}

这似乎不起作用。我需要使用echo语句吗?

2 个答案:

答案 0 :(得分:3)

你必须在php中做回声或在php之外写输入

1)回显显示

<?php if(isset($_POST['newSubmit'])){ 
   echo '<input type="submit" name="newSubmit" id="newSubmit" value="Select" />';    
} ?>

2)写html out side php

<?php if(isset($_POST['newSubmit'])){ ?>
    <input type="submit" name="newSubmit" id="newSubmit" value="Select" />
<?php } ?>

答案 1 :(得分:0)

在php中生成html时,你需要使用echo或者附上php标签

<?php
if(isset($_POST['newSubmit'])){ 
    echo '<input type="submit" name="newSubmit" id="newSubmit" value="Select" />';    
}
?>

<?php
if(isset($_POST['newSubmit'])){?> 
<input type="submit" name="newSubmit" id="newSubmit" value="Select" />    
<?php}?>