在表单的同一页中设置php,只显示php代码
我有这个密码在表单的同一页中设置php,只显示php代码,php,forms,isset,Php,Forms,Isset,我有这个密码 <html> <body> <table cellpadding="5" cellspacing="1" > <tbody class="ui-widget"><form method="post" action="xx.php"> <tr> <td><strong>Name</strong><br /> <input name="name">
<html>
<body>
<table cellpadding="5" cellspacing="1" >
<tbody class="ui-widget"><form method="post" action="xx.php">
<tr>
<td><strong>Name</strong><br />
<input name="name">
</td>
</tr>
<button name='button'>Success Button</button>
</form></div>
<?php
if(isset($_POST['button']))
{ echo "BYE BYE";}
?>
名称
成功按钮
现在的问题是:如果点击按钮,我将获得表单,并在“再见”之后
如果我只想在同一页上写“再见”怎么办
有一种方法可以避免在下次显示HTML代码?在执行PHP代码之前输出HTML。目前它不受if语句的影响。要解决您的特定问题,请将if语句移到顶部,并将HTML代码放在else语句中。像这样的方法应该会奏效:
<?php
if (isset($_POST['button'])) {
echo 'BYE BYE';
} else {
?>
<html>
<body>
<table cellpadding="5" cellspacing="1" >
<tbody class="ui-widget"><form method="post" action="xx.php">
<tr>
<td><strong>Name</strong><br />
<input name="name">
</td>
</tr>
<button name='button'>Success Button</button>
</form></div>
<?php
}
名称
成功按钮
您需要将PHP放在HTML之前,并创建一个if/else:
<?php
if(isset($_POST['button'])) {echo "BYE BYE";}
else {
?>
<html>
<body>
<table cellpadding="5" cellspacing="1" >
<tbody class="ui-widget">
<form method="post" action="xx.php">
<tr>
<td><strong>Name</strong><br />
<input name="name">
</td>
</tr>
<button name='button'>Success Button</button>
</form>
</div>
<?php } ?>
名称
成功按钮
@claud请点击勾号并投票选出正确答案,将您的问题显示为“已解决”好吗?