Jump to content

[SOLVED] Signup with dropdown options


mikebyrne

Recommended Posts

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>

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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;
}

?>

Link to comment
Share on other sites

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());

}

?>

 

Link to comment
Share on other sites

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());


?>

 

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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";
}
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.