Jump to content

Why isn't This Working? (Form Submission)


djcochran

Recommended Posts

I don't understand. This isn't doing anything. I keep trying to fill in the form, but when I hit submit and check my mysql table, nothing has happened. What's going on?

 

*I removed a lot of stuff, like state names and whatnot to save space.

 

<?php
$file = fopen("template.data", "r");
while(!feof($file)) {
$line = fgets($file);
if(preg_match("/@@CONTENT_HERE@@/", $line, $dummyarray)){

print<<<END
  
  <script type="text/javascript">
      var emailRe=/^.+@.+\..{2,3}$/;
      var zipCodeRe=/^[0-9][0-9][0-9][0-9][0-9]$/;
      var telephoneRe=/^[\(]?(\d{3})[\)]?[-\.]?(\d{3})[-\.]?(\d{4})$/;
    
  function validate_form(){
    valid = true;
    if(document.join.lastName.value == ""){
        alert("Please provide your last name.");
        valid = false;
    }
    if(document.join.firstName.value == ""){
        alert("Please provide your first name.");
        valid = false;
    }
    if(document.join.addressOne.value == ""){
        alert("Please provide your address.");
        valid = false;
    }        
    if(document.join.city.value == ""){
        alert("Please provide your city name.");
        valid = false;
    }
    if(document.join.state.value == ""){
        alert("Please select your state.");
        valid = false;
    }
    if(document.join.country.value == ""){
        alert("Please select your country.");
        valid = false;
    }
    if(!zipCodeRe.test(document.join.zipCode.value)){
      alert("Please provide a valid zip code.");
      valid = false;
    }    
    if(!telephoneRe.test(document.join.phoneNumber.value)){
      alert("Please provide a valid telephone number.");
      valid = false;
    }       
    if(!emailRe.test(document.join.emailAddress.value)){
      alert("Please provide a valid email address.");
      valid = false;
    }
    if(document.join.emailAddress.value != document.join.emailVerify.value){
      alert("Email addresses do not match!");
      valid = false;
    }
    if(document.join.password.value.length < 6){
      alert("Password must be at least six characters long.");
      valid = false;
    }       
    if(document.join.password.value != document.join.passwordVerify.value){
      alert("Passwords do not match!");
      valid = false;
    }
    if(document.join.secretQuestion.value == ""){
        alert("Please provide your secret question.");
        valid = false;
    }
    if(document.join.secretQuestionAnswer.value == ""){
        alert("Please provide answer to secret question.");
        valid = false;
    }
    return valid;
  }
  </script>
  
  </DIV> 
  <DIV CLASS="body">
    <FORM NAME="join" ACTION="http://cs-sun2000.uscupstate.edu/~student5/join.php" METHOD="POST" onsubmit="return validate_form();">
      <TABLE>
        <TR>
          <TD>Last Name: </TD>
          <TD> <INPUT TYPE="text" NAME=lastName MAXLENGTH="20" VALUE="" CLASS="textfield"> </TD>
        </TR>
                
        <TR>
          <TD>First Name: </TD>
          <TD> <INPUT TYPE="text" NAME=firstName MAXLENGTH="25" VALUE="" CLASS="textfield"> </TD>
        </TR> 
        
        <TR>
          <TD>Address One: </TD>
				<TD> <INPUT TYPE="text" NAME="addressOne" MAXLENGTH="32" VALUE="" CLASS="textfield"> </TD>
			</TR> 

			<TR>
          <TD>Address Two: </TD>
				<TD> <INPUT TYPE="text" NAME="addressTwo" MAXLENGTH="32" VALUE="" CLASS="textfield"> </TD>
			</TR> 

        <TR>
          <TD>City: </TD>
          <TD> <INPUT TYPE ="text" NAME="city" MAXLENGTH="32" VALUE="" CLASS="textfield"> </TD>
        </TR> 
        
        <TR>
          <TD>State: </TD>
					<TD>
						<SELECT NAME="state" CLASS="textfield"> <OPTION VALUE="">(STATE) </OPTION>

								<OPTION VALUE="AL">
									ALABAMA             
								</OPTION></SELECT>
            </TD>
				</TR> 

				<TR>
					<TD>Country: </TD>
					<TD>
						<SELECT NAME="country" CLASS="textfield"> <OPTION VALUE="">(COUNTRY)</OPTION>

								<OPTION VALUE="ANDORRA">
									ANDORRA
								</OPTION></SELECT>
					</TD>
				</TR> 

				<TR>
					<TD>Zip Code: </TD>
					<TD> <INPUT TYPE="text" NAME="zipCode" MAXLENGTH="10" VALUE="" CLASS="textfield"> </TD>
				</TR>

				<TR>
					<TD>Telephone: </TD>
					<TD> <INPUT TYPE="text" NAME="phoneNumber" MAXLENGTH="16" VALUE="" CLASS="textfield"><I><FONT SIZE="2">Ex. (555)123-4567 or 555-123-1234</FONT></I> </TD>
          </TR>        
  
          <TR>
            <TD>Email: </TD>
            <TD> <INPUT TYPE="text" NAME="emailAddress" MAXLENGTH="100" VALUE="" CLASS="textfield"><I><FONT SIZE="2">Ex. [email protected]</FONT></I></TD>
          </TR> 
          
          <TR>
            <TD>Verify Email: </TD>
            <TD> <INPUT TYPE="text" NAME="emailVerify" MAXLENGTH="100" VALUE="" CLASS="textfield"> </TD>
          </TR> 
            
          <TR>
					<TD>Password: </TD>
				  <TD> <INPUT TYPE="password" NAME="password" MAXLENGTH="64" VALUE="" CLASS="textfield"><I><FONT SIZE="2">Password must contain at least six characters.</FONT></I> </TD>
				</TR> 

				<TR>
				  <TD>Verify Password: </TD>
				  <TD> <INPUT TYPE="password" NAME="passwordVerify" MAXLENGTH="64" VALUE="" CLASS="textfield"> </TD>
				</TR>

				<TR>
				  <TD>Secret Question: </TD>
				  <TD> <INPUT TYPE="text" NAME="secretQuestion" MAXLENGTH="100" STYLE="width:500px"; VALUE="" CLASS="textfield"><BR><I><FONT SIZE="2">Enter a question to be asked in case you forget your paswsword. (MAX LENGTH = 100 characters)</FONT></I></TD>
				</TR>

				<TR>
				  <TD>Answer to Secret Question: </TD>
				  <TD> <INPUT TYPE="text" NAME="secretQuestionAnswer" MAXLENGTH="100" STYLE="width:500px"; VALUE="" CLASS="textfield"><BR><I><FONT SIZE="2">Enter the answer to your secret question. (MAX LENGTH = 100 characters)</FONT></I> </TD>
				</TR>

				<TR>
				   <TD> <BR><BR><INPUT TYPE="submit" NAME="send" VALUE="Submit"> <INPUT TYPE="reset" VALUE="Reset"> </TD> 
				</TR>		
			</TABLE>	
      </FORM>
    </DIV>    
END;

}else if(preg_match("/@@LOGGED_IN@@/", $line, $dummyarray)){ // look for another special marker

   if(isset($_SESSION['name'])){ // check if session variable that indicate user is logged in has been set
      echo "User is logged in";
   }else{
      echo "User is not logged in";
   }

}else{

echo $line;
}; // end else
}; // end while

?>    


<?php
/**** Dealing with the database ****/
// connect to db
$conn = mysql_connect('localhost','xxxx','xxxx') or trigger_error("SQL", E_USER_ERROR); 
$db = mysql_select_db('student5',$conn) or trigger_error("SQL", E_USER_ERROR); 

// INSERT: if we have a name to add...
if($_POST['lastName']) 
   // little bit of cleaning...
   $lastname = mysql_real_escape_string($_POST['lastName']);
   // insert new name into table
if($_POST['firstName']) 
   // little bit of cleaning...
   $firstname = mysql_real_escape_string($_POST['firstName']);
   // insert new name into table
if($_POST['addressOne']) 
   // little bit of cleaning...
   $addressOne = mysql_real_escape_string($_POST['addressOne']);
   // insert new name into table
if($_POST['addressTwo']) 
   // little bit of cleaning...
   $addressTwo = mysql_real_escape_string($_POST['addressTwo']);
   // insert new name into table
if($_POST['city']) 
   // little bit of cleaning...
   $city = mysql_real_escape_string($_POST['city']);
   // insert new name into table
if($_POST['state']) 
   // little bit of cleaning...
   $state = mysql_real_escape_string($_POST['state']);
   // insert new name into table
if($_POST['country']) 
   // little bit of cleaning...
   $country = mysql_real_escape_string($_POST['country']);
   // insert new name into table
if($_POST['zipCode']) 
   // little bit of cleaning...
   $zipcode = mysql_real_escape_string($_POST['zipCode']);
   // insert new name into table
if($_POST['phoneNumber']) 
   // little bit of cleaning...
   $phonenumber = mysql_real_escape_string($_POST['phoneNumber']);
   // insert new name into table
if($_POST['emailAddress']) 
   // little bit of cleaning...
   $emailaddress = mysql_real_escape_string($_POST['emailAddress']);
   // insert new name into table
if($_POST['password']) 
   // little bit of cleaning...
   $password = mysql_real_escape_string($_POST['password']);
   // insert new name into table
if($_POST['secretQuestion']) 
   // little bit of cleaning...
   $secretquestion = mysql_real_escape_string($_POST['secretQuestion']);
   // insert new name into table
if($_POST['secretAnswer']) 
   // little bit of cleaning...
   $secretanswer = mysql_real_escape_string($_POST['secretAnswer']);
   // insert new name into table
   $sql = "INSERT INTO cusinfo (cnum, last_Name, first_Name, address_One, address_Two, city, state, country, zip_Code, phone_Number, email_Address, password, secret_Question, secret_Answer) VALUES ('','$lastname', $firstname', '$addressone', '$addresstwo', '$city', '$state', '$country', '$zipcode', '$phonenumber', '$emailaddress', '$password', '$secretquestion','$secretanswer')";
   $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
?>

 

The php stuff is the top and bottom. Everything in the middle is just the form/html. Also, quick question...do I need to use something special for getting the password instead of just mysql_real_escape_string?

Link to comment
https://forums.phpfreaks.com/topic/153661-why-isnt-this-working-form-submission/
Share on other sites

either use

echo mysql_error($result);

just after the $result line

or

print_r($result);

  this gives you almost too much information

or

echo $sql;

  then run this in your mysql client  phpmyadmin etc

just to make sure the sql statement looks right

I'm sorry. I see it now. I had something in the way blocking the text. I got this error message...

 

Fatal Error: SQL in /export/home/student5/html/join.php on line 1224.

 

This is line 1224

$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.