djcochran Posted April 11, 2009 Share Posted April 11, 2009 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. emailname@xxxxx.com</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? Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted April 11, 2009 Share Posted April 11, 2009 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 Quote Link to comment Share on other sites More sharing options...
djcochran Posted April 11, 2009 Author Share Posted April 11, 2009 I tried adding echo mysql_error($result); and running it, but it didn't do anything. It just sent me back to the page. And it still didn't update the cusinfo table. Is my php code not being executed or something?? Quote Link to comment Share on other sites More sharing options...
djcochran Posted April 11, 2009 Author Share Posted April 11, 2009 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); Quote Link to comment Share on other sites More sharing options...
redarrow Posted April 11, 2009 Share Posted April 11, 2009 Are you sure the database field names match. Quote Link to comment Share on other sites More sharing options...
djcochran Posted April 11, 2009 Author Share Posted April 11, 2009 I think so. I'm using database student5 and inserting a new record into the table cusinfo. I even tried not specifying which columns to put it in (just create insert a new one with all the info) and I still got that error. Quote Link to comment Share on other sites More sharing options...
djcochran Posted April 11, 2009 Author Share Posted April 11, 2009 I've read over it, and I can't seem to find any misspellings or anything. That's what fatal errors usually refer to, right? Syntax kind of stuff? Quote Link to comment Share on other sites More sharing options...
djcochran Posted April 11, 2009 Author Share Posted April 11, 2009 Are you sure the database field names match. What exactly do you mean? I'm fairly new at this. Well...I'm really new at this :-\ Quote Link to comment Share on other sites More sharing options...
djcochran Posted April 12, 2009 Author Share Posted April 12, 2009 Would anyone mind giving this a once over and helping me figure out what my error is? I've been trying different stuff for the past day and a half and can't figure it out. Quote Link to comment Share on other sites More sharing options...
djcochran Posted April 12, 2009 Author Share Posted April 12, 2009 Nevermind. I found the syntax error, but now I have another problem. It enters the data into the table, but for some reason, it's all blank. It doesn't show anything but white space in the table. Quote Link to comment Share on other sites More sharing options...
herghost Posted April 13, 2009 Share Posted April 13, 2009 Try giving your fields ID's from this: <INPUT TYPE="text" NAME=lastName MAXLENGTH="20" VALUE="" CLASS="textfield"> </TD> into this: <INPUT TYPE="text" NAME=lastName MAXLENGTH="20" VALUE="" CLASS="textfield" id="lastName"> </TD> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.