目前,我有一个带有输入(文本)的表单和一个提交表单的按钮。
表单发布到'submit.php'。我希望将表单发布到与表单相同的页面。
我该怎么做?
<form action="submit.php" method="POST">
<input type="text" class="emailField" placeholder="email address" name="email" />
<button type="submit">
<div class="submit" />
</button>
</form>
submit.php
<?php
mysql_connect('localhost', '', '') or die('unable to connect');
mysql_select_db('') or die('unable to select db');
$query = mysql_query("");
if (mysql_num_rows($query) > 0) {
exit("You have already subscribed!");
}
else {
mysql_query("") or die(mysql_error());
exit("You have successfully subscribed!");
}
?>
答案 0 :(得分:5)
我认为你有几个选择。
<?php
if('POST' == $_SERVER['REQUEST_METHOD']) {
// process the form here
}
?>
<form action="" method="POST">
<input type="text" class="emailField" placeholder="email address" name="email" />
<button type="submit">
<div class="submit" />
</button>
</form>
在要显示表单的submit.php
中添加类似内容。
<?php
header('Location: http://example.org/form.php');
exit;
?>