Forum Moderators: coopster
After the user has selected a few options to narrow down some choices of facilities, the one they actually select links them to the signupform.php and carries the facilty_id with it.
ie: signupform.php?facility_id=22
I need this value put into the new users record when they sign-up. I am having trouble grasping how to get the value into the new record.
This form has performed well, with the exception of me wanting to now include this facility_id value when a new user signs up.
Here is my signup form.
<?php
include_once "connection.php";
connect () ;
if (!$_POST['submit']) {
echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n";
echo "<form method=\"post\" action=\"signupform.php\">\n";
echo "<tr><td colspan=\"2\" align=\"center\">Registration Form</td></tr>\n";
echo "<tr><td>Username</td><td><input type=\"text\" name=\"username\"><td></tr>\n";
echo "<tr><td>Password</td><td><input type=\"password\" name=\"password\"><td></tr>\n";
echo "<tr><td>Confirm</td><td><input type=\"password\" name=\"passconf\"><td></tr>\n";
echo "<tr><td>Email</td><td><input type=\"text\" name=\"email\"><td></tr>\n";
echo "<tr><td>Name</td><td><input type=\"text\" name=\"name\"><td></tr>\n";
echo "<tr><td>Facility</td><td><input type=\"text\" name=\"facility_id\"><td></tr>\n";
echo "<tr><td>AIM Address</td><td><input type=\"text\" name=\"aim\"><td></tr>\n";
echo "<tr><td>Comments</td><td><input type=\"text\" name=\"comments\"><td></tr>\n";
echo "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Register\"></td></tr>\n";
echo "</form></table>\n";
}else {
$username = protect($_POST['username']) ;
$password = protect($_POST['password']) ;
$confirm = protect($_POST['passconf']) ;
$email = protect($_POST['email']) ;
$name = protect($_POST['name']) ;
$facility_id = protect($_POST['facility_id']) ;
$aim = protect($_POST['aim']) ;
$comments = protect($_POST['comments']) ;
$toaddress = 'myname@example.com';
$subject = 'New Player Registration';
$mailcontent = 'Customer Name: '.$name."\n"
.'Customer Email: '.$email."\n"
.'Comments: '.$comments."\n"
."Password: \n".$password."\n";
$fromaddress = 'From: webmaster@example.com';
mail($toaddress, $subject, $mailcontent, $fromaddress);
$errors = array() ;
if(!$username) {
$errors[] = "User is not defined!";
}
if(!$password) {
$errors[] = "Password is not defined!";
}
if($password) {
if(!$confirm) {
$errors[] = "Confirm password is not defined!";
}
}
if(!$email) {
$errors[] = "Email is not defined!";
}
if(!$name) {
$errors[] = "Name is not defined!";
}
if(!$aim) {
$errors[] = "AIM Screenname is not defined!";
}
if($password && $confirm) {
if($password != $confirm) {
$errors[] = "Password do not match!";
}
}
if($username) {
$sql = "SELECT * FROM users WHERE username = '{$username}'";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) > 0) {
$errors[] = "The username you supplied is already in use!";
}
}
if($email) {
$sql2 = "SELECT * FROM users WHERE email = '{$email}'";
$res2 = mysql_query($sql2) or die(mysql_error());
if(mysql_num_rows($res2) > 0) {
$errors[] = "The email you supplied is already in use by another user!";
}
}
if($aim) {
$sql3 = "SELECT * FROM users WHERE aim = '{$aim}'";
$res3 = mysql_query($sql3) or die(mysql_error());
if(mysql_num_rows($res3) > 0) {
$errors[] = "The AIM screenname you supplied is already in use by another user!";
}
}
if(count($errors) > 0) {
foreach ($errors AS $error) {
echo $error . "<br>\n";
}
}else {
$sql4 = "INSERT INTO users
(username, password, email, name, facility_id, aim, comments)
VALUES ('$username', '".md5 ($password) ."', '$email', '$name', '$facility_id', '$aim', '$comments')";
$res4 = mysql_query($sql4) or die(mysql_error());
echo "You have successfully registered with the username <b>{$username}</b><br /> and the password is <b>{$password}</b><br /> and your comment {$comments}" ;
}
}
?>
[edited by: eelixduppy at 9:24 pm (utc) on July 10, 2008]
[edit reason] exemplified [/edit]
if (!$_POST['submit']) {
$facility_id = (isset($_GET['facility_id']) && is_numeric($_GET['facility_id'])) ? $_GET['facility_id'] : 0; // a quick check to stop cross site scripting. Default value is 0.
echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n";
echo "<form method=\"post\" action=\"signupform.php\">\n";
echo "<input type=\"hidden\" name=\"facility_id\" value=\"$facility_id\">\n";
... continue as normal
Then when the form is submitted you have facility_id as a $_POST variable just like the others.