Dear Chris,
Thank you for your response. I will make sure to start a new thread for
future.
I tried this but it did not work
if (isset($_POST['title'])) {
$title = htmlentities($_POST['title']);
echo $title;
} else {
$title = '';
}
This part of my code seems to be the problem, Though I dont know why.
if (isset($message))
{
echo "<font color=\"red\">{$message} </font><br>";
echo "You are logged in $user";
?>
Cause if change the if statement to
if (!isset($message))
the values are saved. But I need this to display the message..
if (empty($title) || empty($Email) || empty($Phone) || empty($Details)
|| empty($Keywords) || empty($City))
{
$message = "Please fill all the required fields.";
// Now, redirect the browser to the current page
session_start();
header("Location: form.php?message=" . urlencode($message));
exit;
}
Here is my structure..
<?php
//check is there is any message, which I expect to have when the user
come on this page. Then show the user form
if (isset($message))
{
echo "<font color=\"red\">{$message} </font><br>";
echo "You are logged in $user";
?>
HTML CODE FOR FORM..
<?php PHP code starts here
}//end of IF
else
{
if (empty($title) || empty($Email) || empty($Phone) || empty($Details)
|| empty($Keywords) || empty($City) || empty($State) || empty($ZIP) ||
empty($Type))
{
$message = "Please fill all the required fields.";
// Now, redirect the browser to the current page
session_start();
header("Location: form.php?message=" . urlencode($message));
exit;
}
here is the code to insert the entries into the database..
where it goes back to the same page for each error message
header("Location: form.php?message=" . urlencode($message));
exit;
Or come back to the same page with a valid message for another entry..
}//end of else...
?> end of php code
I am confused what I am doing wrong..
Again thank for your response.
-Jai
Chris wrote:
Jai Rangi wrote:
Greeting,
I hope this is the right place for this. If not please guide me.
I am having problem with my "Form". Code is below. I want to generate
an error message if the required fields are not filled. If they are
filled then I want to add them to the database and display the form
again to make another entry. Database part is working fine. But when
it exist with an error for blank entry, it wipe out all the values
the user has entered, how can I save user input in case user does not
have to enter all the values again.
Thank you for help.
Start a new thread next time please - don't reply to an existing
thread. It makes it really hard to follow.
<tr><td><font color=<? echo($FONTCOLOR); ?>><i>Main Keywords for this
search: * </i></font></td><td><input type="text" name="Keywords"
size=60></td></tr>
You're not including the post values.
It should be something like:
......<input type="text" name="Keywords" value="<?php echo
(isset($_POST['Keywords'])) ? htmlentities($_POST['Keywords']) : '';
?>" size=60>......
or you could check everything before hand:
if (isset($_POST['Keywords'])) {
$keywords = htmlentities($_POST['Keywords']);
} else {
$keywords = '';
}
...
<input type="text" name="Keywords" value="<?php echo $keywords; ?>"
size=60>
...
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php