Note that there are some explanatory texts on larger screens.

plurals
  1. POTwo forms, one php script - success message echoed beneath form
    primarykey
    data
    text
    <p>I have two forms on a single PHP page. The first asking for an email and the second asking for feedback. Both forms are named differently and work. I have the php script working and results going to two different databases so all good there. </p> <p>The problem arises when I want a confirmation message to appear just beneath each form. At the moment the confirmation messages appear at the top of the page when a user clicks the 'Subscribe' or 'Post Feedback' buttons. How can I get each confirmation message to appear just beneath the forms (indicated by the HTML comment tags in the form code below)? </p> <p>I am sure there is a relatively straightforward way of doing this, but I just don't see it.</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); echo "&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); echo "&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;head&gt; &lt;style type="text/css"&gt; #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;} &lt;/style&gt; &lt;/head&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;/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;/form&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Thanks for any help.</p> <p>Andy ;-)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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