I am a newbie and am at a loss on how to clear field of a form.
My current form is the tradition form that check to see if it has been submitted.
After it has, validation of each field is performed and if all is ok a record is inserted in the data base. However, if validation fails, the error and the fields previously entered are redisplayed. When the error is corrected the form is again submitted and record inserted. At this point, I am trying to clear the form (reset it) by using first: clearing the $_post array and checking for empty did not work
second: setting and destroyinga session..did not work....any ideas? Thanks in advance.

I think that you need to post some code before anyone can really comment.

posting code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?php
//allow sessions to be passed so we can see if the user is logged in
session_start();




//connect to the database so we can check, edit, or insert data to our users table
mysql_connect("localhost", "cccgawm", "magyar01") or die(mysql_error());

echo "Connection to the server was successful!<br/>";
mysql_select_db("members_db") or die(mysql_error());
echo "Database was selected!<br/>";
 
//include out functions file giving us access to the protect() function
include "./functions.php";
// echo "status of error $_SESSION['errs']";
if(!isset($_POST['submit']))
       {
 			$firstname = '';
			$lastname = '';
			$address1 ='';
			$city = '';
			$state = '';
			$zip = '';
			$phone = '';	
			$spouse = '';
			$email = '';}
?>
<html>
	<head>
<html><head>
		<?php
		
 
		//Check to see if the form has been submitted
		if(isset($_POST['submit'])){
 
			//protect and then add the posted data to variables

			$firstname = protect($_POST['firstname']);
			$lastname = protect($_POST['lastname']);
			$address1 = protect($_POST['address1']);

			$city = protect($_POST['city']);
			$state = protect($_POST['state']);
			$zip = protect($_POST['zip']);
			$phone = protect($_POST['phone']);
	
			$spouse = protect($_POST['spouse']);
			$email = protect($_POST['email']);
			$password = 'cccwga';
			$assoc = 'w';
			$active = '0';

			$username= strtolower($lastname);
			$to = "cccgatest@localhost";
			$subject = "CCCWGA Roster Login";
			$from = "cccgatest@localhost";
			$headers = "From: $from";
			//check to see if any of the boxes were not filled in
			if(!$firstname || !$lastname || !$address1||
                           !$city || !$state || !$zip||
                           !$phone || !$spouse || !$email){
				//if any weren't display the error message
				echo "<center>You need to fill in all of the required filds!</center>";
				 $_SESSION["errs"] = 1; 
			}else{
				//if all were filled in continue checking
 
				//Check if the wanted username is more than 32 or less than 3 charcters long
				if(strlen($username) > 32 || strlen($username) < 3){
					//if it is display error message
					 $_SESSION["errs"] = 1; 
					echo "<center>Your <b>Username</b> must be between 3 and 32 characters long!</center>";
				}else{
					//if not continue checking
 
					//select all the rows from out users table where the posted username matches the username stored
					$res = mysql_query("SELECT * FROM `players` WHERE `username` = '".$username."'");
					$num = mysql_num_rows($res);
					

 
					//check if theres a match
					if($num == 1){
						//if yes the username is taken so display error message
						echo  "<center>The <b>Username</b> you have chosen is already taken!</center>";
						 $_SESSION["errs"] = 1; 
					}else{
						//otherwise continue checking
 
						//check if the password is less than 5 or more than 32 characters long
						if(!preg_match("/^[0-9]{5}$/", $zip)){
							//if it is display error message
							echo "<center>Zip must be 5 numeric!</center>";  $_SESSION["errs"] = 1; 
						}else{
							//else continue checking
 
							//check if the password and confirm password match
							if(! preg_match('/[0-9]{3}-[0-9]{3}-[0-9]{4}/', $phone)){
								//if not display error message
								echo "<center>The <b>Phone number format is 111-222-3333!</center>";
								 $_SESSION["errs"] = 1; 
							}else{
								//otherwise continue checking
 
								//Set the format we want to check out email address against
								$checkemail = "/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i";
 
								//check if the formats match
					            if(!preg_match($checkemail, $email)){
					            	//if not display error message
					                echo "<center>The <b>E-mail</b> is not valid, must be name@server.xxx !</center>";
									 $_SESSION["errs"] = 1; 
					            }else{
					            	//if they do, continue checking

					            	//select all rows from our users table where the emails match
					            	$res1 = mysql_query("SELECT * FROM `players` WHERE `eaddr` = '".$email."'");
					            	$num1 = mysql_num_rows($res1);
 
					            	//if the number of matchs is 1
					            	if($num1 == 1){
					            		//the email address supplied is taken so display error message
										echo "<center>The <b>E-mail</b> address you supplied is already taken</center>";
									}else{
										//finally, otherwise register there account
 
										//time of register (unix)
						            	$registerTime = date('U');
 
						            	//make a code for our activation key
						            	$code = md5($username).$registerTime;

						            	//insert the row into the database
										$res2 = mysql_query("INSERT INTO players

(username, fname, lname, addr, city, zip, state, phone, spouse, eaddr, assoc, pwrd)

 VALUES('
".$username."','
".$firstname."','
".$lastname."','
".$address1."','
".$city."','
".$zip."','
".$state."','
".$phone."','
".$spouse."','
".$email."','
".$assoc."','
".$password."')");


 
//send the email with an email containing the activation link to the supplied email address


$message = "$firstname,\nThank you for registering with the CCCWGA.\n\nHere is your activation link. If the link doesn't //work copy //and paste it into your browser address bar.\n\nhttp://www.cccga.info/activate.php?code=$code.";
			
//mail($to,$subject,$message,$headers);
unset($_POST['submit']);

session_destroy();

								  

										//display the success message
										echo "<center>You have successfully registered $firstname. Mail has been sent.</center>";
									}
								}
							}
						}
					}
				}
			}
		}
 
		?>
		<div id="border">
			<form action="wmentry.php" method="post">
				<table cellpadding="2" cellspacing="0" border="0">

					<tr>
						<td>First Name: </td>
						<td><input type="text" name="firstname"value="<?php echo $firstname ?>" /></td>
					</tr>
					<tr>
						<td>Last Name: </td>
						<td><input type="text" name="lastname" value="<?php echo $lastname ?>"/></td>
					</tr>

Clear out your db credentials and email settings while you still can. Next time, remove them before posting.

They are bogus

i am a newbie and am at a loss on how to clear field of a form.
My current form is the tradition form that check to see if it has been submitted.
After it has, validation of each field is performed and if all is ok a record is inserted in the data base. However, if validation fails, the error and the fields previously entered are redisplayed. When the error is corrected the form is again submitted and record inserted. At this point, i am trying to clear the form (reset it) by using first: Clearing the $_post array and checking for empty did not work
second: Setting and destroyinga session..did not work....any ideas? Thanks in advance.

can you post your code here.

You need to clear the variables on lines 143-154 too.

Line 19 clears those variables when $_post ("submit") is unset after the write is performed at line 164 at least i think so

I don't. Try it...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.