1 つの PHP ページに 2 つのフォームがあります。最初に電子メールを求め、2 番目にフィードバックを求めます。どちらの形式も名前が異なり、機能します。私はphpスクリプトが機能していて、結果が2つの異なるデータベースに送られるので、すべて問題ありません。
各フォームのすぐ下に確認メッセージを表示したい場合に問題が発生します。現時点では、ユーザーが [購読] または [フィードバックを投稿] ボタンをクリックすると、ページの上部に確認メッセージが表示されます。各確認メッセージをフォームのすぐ下に表示するにはどうすればよいですか (以下のフォーム コードの HTML コメント タグで示されます)。
これを行う比較的簡単な方法があると確信していますが、私にはわかりません。
<?php
if(isset($_POST['submit'])){
if($_POST['submit'] == 'Subscribe'){
//process form1
$email = str_replace("'", "\'", htmlentities($_POST['email']));
$dbc = mysqli_connect('localhost', 'root', 'password', 'newslist')
or die('Error no connection to server.');
$query = "INSERT INTO email_list(email, submitted) VALUES ('$email', now())";
$result = mysqli_query($dbc, $query) or die ('Error querying database.');
mysqli_close($dbc);
echo "<p span style=\"color:#c3593c; font-weight:bold; font-size:18px; text-align:center\">Thanks for signing up.</span></p>";
}
else if($_POST['submit'] == 'Post Feedback'){
//process form2
$feedback = str_replace("'", "\'", htmlentities($_POST['feedback']));
$dbc = mysqli_connect('localhost', 'root', 'password', 'feedbacklist')
or die('Error no connection to server.');
$query = "INSERT INTO feedback(feedback, submitted) VALUES ('$feedback', now())";
$result = mysqli_query($dbc, $query) or die ('Error querying database.');
mysqli_close($dbc);
echo "<p span style=\"color:#c3593c; font-weight:bold; font-size:18px; text-align:center\">Thanks for the feedback.</span></p>";
}
}
?>
<html>
<head>
<style type="text/css">
#newsletter, #feedback{
padding: 15px;
background-color: #E4E4E4;
border: 1px solid #ccc;
width: 300px;}
#newsletter h2, #feedback h2{
margin: 0;
padding-bottom: 3px;
font-size: 19px;
color: #c3593c;
font-family:verdana, arial, sans-serif;}
#newsletter p, #feedback p{
font-family:verdana, arial, sans-serif;
margin: 0;}
</style>
</head>
<body>
<div id="newsletter">
<h2>Newsletter</h2>
<p>Subscribe to our newsletter.</p><br />
<form name="mailinglist" method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>">
<p><strong>Email</strong> <input type="text" name="email" />
<input name="submit" type="submit" value="Subscribe" /></p>
<!--I want the first message echoed here once & only if the first form has been submitted-->
</form>
</div>
<br /><br />
<div id="feedback">
<h2>Feedback</h2>
<p>Post your feedback.</p><br />
<form name="feedback" method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>">
<p>Your Suggestion:<br /><textarea name="feedback" rows="8" cols="30"></textarea>
<input name="submit" type="submit" value="Post Feedback" /></p>
<!--I want the second message echoed here once & only if the second form has been submitted-->
</form>
</div>
</body>
</html>
助けてくれてありがとう。
アンディ ;-)