Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Using your code, I would do it like this:</p> <pre><code>&lt;?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); $subscribe_message = "&lt;p span style=\"color:#c3593c; font-weight:bold; font-size:18px; text-align:center\"&gt;Thanks for signing up.&lt;/span&gt;&lt;/p&gt;"; } 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); $feedback_message = "&lt;p span style=\"color:#c3593c; font-weight:bold; font-size:18px; text-align:center\"&gt;Thanks for the feedback.&lt;/span&gt;&lt;/p&gt;"; } } ?&gt; &lt;html&gt; ... &lt;body&gt; &lt;div id="newsletter"&gt; &lt;h2&gt;Newsletter&lt;/h2&gt; &lt;p&gt;Subscribe to our newsletter.&lt;/p&gt;&lt;br /&gt; &lt;form name="mailinglist" method="post" action="&lt;?php echo htmlentities($_SERVER['PHP_SELF']);?&gt;"&gt; &lt;p&gt;&lt;strong&gt;Email&lt;/strong&gt; &lt;input type="text" name="email" /&gt; &lt;input name="submit" type="submit" value="Subscribe" /&gt;&lt;/p&gt; &lt;!--I want the first message echoed here once &amp; only if the first form has been submitted--&gt; &lt;? echo $subscribe_message; ?&gt; &lt;/form&gt; &lt;/div&gt; &lt;br /&gt;&lt;br /&gt; &lt;div id="feedback"&gt; &lt;h2&gt;Feedback&lt;/h2&gt; &lt;p&gt;Post your feedback.&lt;/p&gt;&lt;br /&gt; &lt;form name="feedback" method="post" action="&lt;?php echo htmlentities($_SERVER['PHP_SELF']);?&gt;"&gt; &lt;p&gt;Your Suggestion:&lt;br /&gt;&lt;textarea name="feedback" rows="8" cols="30"&gt;&lt;/textarea&gt; &lt;input name="submit" type="submit" value="Post Feedback" /&gt;&lt;/p&gt; &lt;!--I want the second message echoed here once &amp; only if the second form has been submitted--&gt; &lt;? echo $feedback_message?&gt; &lt;/form&gt; &lt;/div&gt; &lt;/body&gt; </code></pre> <p></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload