revraz Posted December 8, 2007 Share Posted December 8, 2007 Last try before I build a DB to try it <body> <form name="form1" method="post" action="signupsnake.php"> <table align="center"> <tr valign="baseline"> <td>Name:</td> <td><input type="text" name="name" value="" size="32"></td> </tr> <tr valign="baseline"> <td >Age:</td> <td><input type="number" name="Age" value="" size="32"></td> </tr> <tr valign="baseline"> <td>Location:</td> <td><input type="text" name="Location" value="" size="32"></td> </tr> <tr> <td>Position Applying For</td> <td> <select name="mydropdown1" size="1"> <option value="Option">Please Select Option</option> <option value="Help Operator">Help Operator</option> <option value="Moderator">Moderator</option> <option value="Senior Moderator">Senior Moderator</option> <option value="IRCop">IRCop</option> <option value="Administrator">Administrator</option> </select> </td> </tr> <tr valign="baseline"> <td>Reason for Application:</td> <td><input type="text" name="Reason" value="" size="32"></td> </tr> <tr> <td>Do you work for any chatsite?</td> <td> <select name="mydropdown2" size="1"> <option value="YES">YES</option> <option value="NO">NO</option> </select> </td> </tr> <tr valign="baseline"> <td>If so, Which one?:</td> <td><input type="text" name="which" value="" size="32"></td> </tr> <tr> <td><input type="submit" value="Apply"></td> </tr> </table> </form> </body> Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted December 8, 2007 Author Share Posted December 8, 2007 No still the same My code is: <body> <form name="form1" method="post" action="signupsnake.php"> <table align="center"> <tr valign="baseline"> <td>Name:</td> <td><input type="text" name="name" value="" size="32"></td> </tr> <tr valign="baseline"> <td >Age:</td> <td><input type="number" name="Age" value="" size="32"></td> </tr> <tr valign="baseline"> <td>Location:</td> <td><input type="text" name="Location" value="" size="32"></td> </tr> <tr> <td>Position Applying For</td> <td> <select name="mydropdown1" size="1"> <option value="Option">Please Select Option</option> <option value="Help Operator">Help Operator</option> <option value="Moderator">Moderator</option> <option value="Senior Moderator">Senior Moderator</option> <option value="IRCop">IRCop</option> <option value="Administrator">Administrator</option> </select> </td> </tr> <tr valign="baseline"> <td>Reason for Application:</td> <td><input type="text" name="Reason" value="" size="32"></td> </tr> <tr> <td>Do you work for any chatsite?</td> <td> <select name="mydropdown2" size="1"> <option value="YES">YES</option> <option value="NO">NO</option> </select> </td> </tr> <tr valign="baseline"> <td>If so, Which one?:</td> <td><input type="text" name="which" value="" size="32"></td> </tr> <tr> <td><input type="submit" value="Apply"></td> </tr> </table> </form> </body> <?php include('config1.php'); // table name $tbl_name=applications; // values sent from form $name=$_POST['name']; $Age=$_POST['Age']; $Location=$_POST['Location']; $mydropdown1=$_POST['mydropdown1']; $Reason=$_POST['Reason']; $mydropdown2=$_POST['mydropdown2']; $which=$_Post['which'] ; echo $name; echo $Age; echo $Location; echo $mydropdown1; echo $Reason; echo $mydropdown2; echo $which; // Insert data into database $sql="INSERT INTO $tbl_name(Username,Age,Location,Position,Reason,Workonsite,Whatsite)VALUES('$name', '$Age', '$Location', '$mydropdown1', '$Reason','$mydropdown2', '$which')"; $result=mysql_query($sql)or die(mysql_error()); ?> And the SQL is: CREATE TABLE `applications` ( `Userid` int(11) NOT NULL auto_increment, `Username` varchar(20) collate latin1_general_ci default NULL, `Age` int(11) default NULL, `Location` varchar(25) collate latin1_general_ci default NULL, `Position` varchar(40) collate latin1_general_ci default NULL, `Reason` varchar(47) collate latin1_general_ci default NULL, `Workonsite` varchar(3) collate latin1_general_ci default NULL, `Whatsite` varchar(12) collate latin1_general_ci default NULL, PRIMARY KEY (`Userid`) ) ENGINE=MyISAM AUTO_INCREMENT=20 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci Quote Link to comment Share on other sites More sharing options...
revraz Posted December 8, 2007 Share Posted December 8, 2007 This works for me <?php //Check for Submit if (!$_POST['submit']) { ?> <form name="form1" method="post" action="<?php $_SERVER ['PHP_SELF']?>"> <table align="center"> <tr valign="baseline"> <td>Name:</td> <td><input type="text" name="name" value="" size="32"></td> </tr> <tr valign="baseline"> <td >Age:</td> <td><input type="number" name="age" value="" size="32"></td> </tr> <tr valign="baseline"> <td>Location:</td> <td><input type="text" name="location" value="" size="32"></td> </tr> <tr> <td>Position Applying For</td> <td> <select name="mydropdown1" size="1"> <option value="Option">Please Select Option</option> <option value="Help Operator">Help Operator</option> <option value="Moderator">Moderator</option> <option value="Senior Moderator">Senior Moderator</option> <option value="IRCop">IRCop</option> <option value="Administrator">Administrator</option> </select> </td> </tr> <tr valign="baseline"> <td>Reason for Application:</td> <td><input type="text" name="reason" value="" size="32"></td> </tr> <tr> <td>Do you work for any chatsite?</td> <td> <select name="mydropdown2" size="1"> <option value="YES">YES</option> <option value="NO">NO</option> </select> </td> </tr> <tr valign="baseline"> <td>If so, Which one?:</td> <td><input type="text" name="which" value="" size="32"></td> </tr> <tr> <td><input type="submit" name="submit" value="Apply"></td> </tr> </table> </form> </body> <?php } else { // values sent from form $name=$_POST['name']; $age=$_POST['age']; $location=$_POST['location']; $mydropdown1=$_POST['mydropdown1']; $reason=$_POST['reason']; $mydropdown2=$_POST['myrdopdown2']; $which=$_POST['which']; echo $name; echo $age; echo $location; echo $mydropdown1; echo $reason; echo $mydropdown2; echo $which; } ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted December 8, 2007 Share Posted December 8, 2007 Modified to fit your DB <?php //Check for Submit if (!$_POST['submit']) { ?> <form name="form1" method="post" action="<?php $_SERVER ['PHP_SELF']?>"> <table align="center"> <tr valign="baseline"> <td>Name:</td> <td><input type="text" name="name" value="" size="32"></td> </tr> <tr valign="baseline"> <td >Age:</td> <td><input type="number" name="age" value="" size="32"></td> </tr> <tr valign="baseline"> <td>Location:</td> <td><input type="text" name="location" value="" size="32"></td> </tr> <tr> <td>Position Applying For</td> <td> <select name="mydropdown1" size="1"> <option value="Option">Please Select Option</option> <option value="Help Operator">Help Operator</option> <option value="Moderator">Moderator</option> <option value="Senior Moderator">Senior Moderator</option> <option value="IRCop">IRCop</option> <option value="Administrator">Administrator</option> </select> </td> </tr> <tr valign="baseline"> <td>Reason for Application:</td> <td><input type="text" name="reason" value="" size="32"></td> </tr> <tr> <td>Do you work for any chatsite?</td> <td> <select name="mydropdown2" size="1"> <option value="YES">YES</option> <option value="NO">NO</option> </select> </td> </tr> <tr valign="baseline"> <td>If so, Which one?:</td> <td><input type="text" name="which" value="" size="32"></td> </tr> <tr> <td><input type="submit" name="submit" value="Apply"></td> </tr> </table> </form> </body> <?php } else { include('config1.php'); // table name $tbl_name= "applications"; // values sent from form $name=$_POST['name']; $age=$_POST['age']; $location=$_POST['location']; $mydropdown1=$_POST['mydropdown1']; $reason=$_POST['reason']; $mydropdown2=$_POST['mydropdown2']; $which=$_POST['which']; echo $name; echo $age; echo $location; echo $mydropdown1; echo $reason; echo $mydropdown2; echo $which; // Insert data into database $sql="INSERT INTO $tbl_name (Username, Age, Location, Position, Reason, Workonsite, Whatsite) VALUES ('$name', '$age', '$location', '$mydropdown1', '$reason','$mydropdown2', '$which')"; $result=mysql_query($sql)or die(mysql_error()); } ?> Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted December 8, 2007 Author Share Posted December 8, 2007 I get an access forbidden error the page goes to http://localhost/%3C?php%20$_SERVER%20['PHP_SELF']?%3E How can i modify this?? Quote Link to comment Share on other sites More sharing options...
revraz Posted December 8, 2007 Share Posted December 8, 2007 Broken back to two <form name="form1" method="post" action="signupsnake.php"> <table align="center"> <tr valign="baseline"> <td>Name:</td> <td><input type="text" name="name" value="" size="32"></td> </tr> <tr valign="baseline"> <td >Age:</td> <td><input type="number" name="age" value="" size="32"></td> </tr> <tr valign="baseline"> <td>Location:</td> <td><input type="text" name="location" value="" size="32"></td> </tr> <tr> <td>Position Applying For</td> <td> <select name="mydropdown1" size="1"> <option value="Option">Please Select Option</option> <option value="Help Operator">Help Operator</option> <option value="Moderator">Moderator</option> <option value="Senior Moderator">Senior Moderator</option> <option value="IRCop">IRCop</option> <option value="Administrator">Administrator</option> </select> </td> </tr> <tr valign="baseline"> <td>Reason for Application:</td> <td><input type="text" name="reason" value="" size="32"></td> </tr> <tr> <td>Do you work for any chatsite?</td> <td> <select name="mydropdown2" size="1"> <option value="YES">YES</option> <option value="NO">NO</option> </select> </td> </tr> <tr valign="baseline"> <td>If so, Which one?:</td> <td><input type="text" name="which" value="" size="32"></td> </tr> <tr> <td><input type="submit" name="submit" value="Apply"></td> </tr> </table> </form> </body> <?php include('config1.php'); // table name $tbl_name= "applications"; // values sent from form $name=$_POST['name']; $age=$_POST['age']; $location=$_POST['location']; $mydropdown1=$_POST['mydropdown1']; $reason=$_POST['reason']; $mydropdown2=$_POST['mydropdown2']; $which=$_POST['which']; echo $name; echo $age; echo $location; echo $mydropdown1; echo $reason; echo $mydropdown2; echo $which; // Insert data into database $sql="INSERT INTO $tbl_name (Username, Age, Location, Position, Reason, Workonsite, Whatsite) VALUES ('$name', '$age', '$location', '$mydropdown1', '$reason','$mydropdown2', '$which')"; $result=mysql_query($sql)or die(mysql_error()); ?> Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted December 8, 2007 Author Share Posted December 8, 2007 That works perfect now! CHEERS AGAIN REV Quote Link to comment Share on other sites More sharing options...
revraz Posted December 8, 2007 Share Posted December 8, 2007 Now you need to make sure you add some validation to the form fields and do some sanitization on them before you insert. Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted December 8, 2007 Author Share Posted December 8, 2007 What would you recommend? Quote Link to comment Share on other sites More sharing options...
revraz Posted December 8, 2007 Share Posted December 8, 2007 Check to make sure each $_POST value isnt empty. Check the Age value to make sure it's numeric. And on each line here you want to do something like $name=mysql_real_escape_string ($_POST['name']); before you insert. Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted December 8, 2007 Author Share Posted December 8, 2007 yeah good piont. I wasnt planning on doing the validation because its not for me but I guess I better make an attempt at it! Wiil i do the "$name=mysql_real_escape_string ($_POST['name']);" on the html doc or the php?? Quote Link to comment Share on other sites More sharing options...
revraz Posted December 8, 2007 Share Posted December 8, 2007 PHP It also requires a connection to the DB, but you already have that covered. Quote Link to comment Share on other sites More sharing options...
revraz Posted December 8, 2007 Share Posted December 8, 2007 Here is what I normally do, you can copy paste as you see fit and modify. <?php $errorList = array(); $uname = mysql_real_escape_string ($_POST['uname']); $pw = mysql_real_escape_string ($_POST['password']); $email = mysql_real_escape_string ($_POST['email']); $fname = mysql_real_escape_string ($_POST['fname']); $lname = mysql_real_escape_string ($_POST['lname']); $phone = mysql_real_escape_string ($_POST['phone']); //validate input if (trim (strlen($uname)) >= 6) { if (checkUnique ("users", "uname", $uname) == FALSE) { $errorList[] = 'Username Taken, please try another Username'; } } else { $errorList[] = 'Invalid entry: User Name'; } if (trim (strlen($pw)) <= 5) { $errorList[] = 'Invalid entry: Password'; } if (trim ($email) != "") { if (checkUnique ("users", "uemail", $email) == FALSE) { $errorList[] = 'Email Taken, did you forget your PW?'; } } else { $errorList[] = 'Invalid entry: Email'; } if (trim ($fname) == "") { $errorList[] = 'Invalid entry: First Name'; } if (trim ($lname) == "") { $errorList[] = 'Invalid entry: Last Name'; } if (trim (strlen($phone)) <= 9) { $errorList[] = 'Invalid entry: Phone'; } //error checking if (sizeof ($errorList) == 0) { $pw=sha1($pw); $query = "INSERT INTO users (ufname, ulname, uname, upw, uemail, uphn, regdate) VALUES ('$fname', '$lname', '$uname', '$pw', '$email', '$phone', NOW())"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); echo 'Update Sucessful. Following entry added: <br />'; echo $uname . "<br />"; echo $fname . "<br />"; echo $lname . "<br />"; echo $email . "<br />"; echo $phone . "<br />"; echo '<font size=-1><a href=login.php>Go to Login Page</a>.</font>'; } else { //errors echo 'Following errors were found:'; echo '<br />'; echo '<ul>'; for ($x=0; $x<sizeof($errorList); $x++) { echo "<li>$errorList[$x]"; } echo '</ul><br />'; echo "Hit BACK to re-enter information"; } ?> Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted December 8, 2007 Author Share Posted December 8, 2007 The validation I would require (at a glance) should be: 1) Only numeric can be entered on the age field 2) A positon from (mydropdown1) HAS to be selected and cant be left "Please Select Option" 3) 1 option from (mydropdown2) HAS to be selected and cant be "Please select Option" 4) I'll need a simple If statement saying IF the user has selected they work for a chatsite they HAVE to fill out the "If so, which one" filed Again, If you can help me out it would be great 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.