I wouldn't use header() in this case, unless you plan to create an ungodly looking URL to pass with it.. All you really need to do is point the form to a PHP script that validates the information. Then at the end of that script either include() the form hander if it's valid, or print an error message if it's not valid. It would be this simple..
test.html ----------------------- <form method="post" action="validate.php"> <input type="text" name="email"> <input type="submit"> </form> ---------------------- validate.php ---------------------- <? $query = "SELECT * FROM mytable WHERE email = '$email'"; $result = mysql_query($query, $db); $num = mysql_num_rows($result); if ($num > 0) include ("formhander.php"); else echo "Email already exists."; ?> A more appropriate place to use header() would be in the "else" statement to return to the original .html page. You could even brand the .html page with the error message by placing a unique comment such as <!-ERROR-> within the html, then do something like... fopen($HTTP_REFERER, "r"); $file = fread($fp, 10000); $file = str_replace("<!-ERROR->", $error, $file); echo $file; And that's about as sophisticated as you would ever need to get in this case. -Kevin ----- Original Message ----- From: "Jim lucas" <[EMAIL PROTECTED]> To: "Don" <[EMAIL PROTECTED]>; "php list" <[EMAIL PROTECTED]> Sent: Friday, May 31, 2002 2:56 PM Subject: Re: [PHP] Running a script to check something before submitting a form. Can this be done? > you will have to do this with javascript on the client side with an > onClick() call in the submit button. but the bad thing is, you wont be > able to check this with the mysql db, unless you load the entire field set > into the current page. > > my suggestion would be to send the form to one single page no-matter what. > do the validating and then if the email address isn't there, redirect with > the php header() function to the custom page that you are talking about. > > Jim lucas > ----- Original Message ----- > From: "Don" <[EMAIL PROTECTED]> > To: "php list" <[EMAIL PROTECTED]> > Sent: Friday, May 31, 2002 1:46 PM > Subject: [PHP] Running a script to check something before submitting a form. > Can this be done? > > > Hi, > > I think I need to use PHP here which is why I'm posting to this ng. I have > a form that upon the user pressing submit, calls a PHP form handler. What > I'd like to do is upon the user pressing submit, I need to validate an email > field within a MySQL database and only if it does NOT exist, call the form > handler. If it exists, I'll juets return a custom page and NOT call the > form handler. I'm wondering if I need some JavaScript here? > > If PHP is not involved, I apologize for the post. > > Don > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php