Wondering if someone can help. I have an online form, which contains a textarea and when data is entered into that textarea and submit is hit it loads a second form, where I capture more data from the user at this point I want to add the data to the database and check for errors.
An example of what I mean can be found Here please feel free to test and see what I mean
Now my problem is when I am in the second form. When I fill in the details on this form I want to post these details to a MYSQL database then either return a success message on the second saying everything has been entered fine, or produce error messages in the second form saying fields were not filled in. Anyone help? Here’s my code:
function box() {
//* 1) When page loads this first form loads
if (!(isset($_POST['Submit']))) {
$output = '
<form action="" method="post">
<textarea name="comments" onfocus="this.value=\\'\\'; return false;"></textarea><br />
<button name="Submit" type="submit" value="Submit">Post</button>
</form>';
} else {
if (isset($_POST['Submit'])) {
if ($comments === '') { $errors[] = " You forgot to enter any comments.<br />"; }
if ($your_name === '') { $errors[] = " You forgot to enter your name.<br />"; }
if ($your_email === '') { $errors = "You forgot to enter your email.<br />"; }
if(count($errors) == 0) {
$SQL = "Insert into community_noticeboard (your_name,your_email,comments) values('$_POST['name']','$_POST['your_email']','$_POST['comments']')";
$RES = mysql_query($SQL) or die (mysql_error());
$MSG = "You have added your details correctly";
} else {
$error = "<br /><span style='color: #CC0000;'>" . implode(' ', $errors) . "</span>";
}
}
//* 2) Load this page when you have clicked 'Submit'. Then when you fill in the details they are submitted to DB, but you remain on this page with a error or success message?
$output = '
<form action="" method="post">
'.$MSG.'
Name:</label><input type="text" id="Your Name" name="your_name"></br />
Email:</label><input type="text" id="Your Email" name="your_email"></br />
<button name="Submission" type="submit" value="Submission">Post</button>
</form>';
}
return $output;
}
echo box();
Thanks