Hi
I want to try and find out where I am going wrong with my multi selection form field.
I have a multi selection form field which allows the users to choose more than one selection from the list. Once the form is submitted I want to have each selection show up in the field I have setup in mysql table.
At the moment it only enters one of the selected options
How do i make it enter all of the selection, I have pasted my full php and html code below.
If you can help I would appreciate it.
<?php
// let's initialize vars to be printed to page in the HTML section so our script does not return errors
// they must be initialized in some server environments
$errorMsg = "";
$firstname = "";
$surname = "";
$gender = "";
$email1 = "";
$email2 = "";
$pass1 = "";
$pass2 = "";
$website = "";
$facebook = "";
$myspace = "";
$bio = "";
$location = "";
$venue = "";
$special = "";
// This code runs only if the form submit button is pressed
if (isset ($_POST['firstname'])){
/* Example of cleaning variables in a loop
$vars = "";
foreach ($_POST as $key => $value) {
$value = stripslashes($value);
$vars .= "$key = $value<br />";
}
print "$vars";
exit();
*/
$firstname = $_POST['firstname'];
$surname = $_POST['surname'];
$gender = $_POST['gender'];
$email1 = $_POST['email1'];
$email2 = $_POST['email2'];
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];
$website = $_POST['website'];
$facebook = $_POST['facebook'];
$myspace = $_POST['myspace'];
$bio = $_POST['bio'];
$location = $_POST['location'];
$venue = $_POST['venue'];
$special = $_POST['special'];
$humancheck = $_POST['humancheck'];
$firstname = stripslashes($firstname);
$surname = stripslashes($surname);
$email1 = stripslashes($email1);
$pass1 = stripslashes($pass1);
$email2 = stripslashes($email2);
$pass2 = stripslashes($pass2);
$website = stripslashes($website);
$facebook = stripslashes($facebook);
$myspace = stripslashes($myspace);
$bio = stripslashes($bio);
$firstname = strip_tags($firstname);
$surname = strip_tags($surname);
$email1 = strip_tags($email1);
$pass1 = strip_tags($pass1);
$email2 = strip_tags($email2);
$pass2 = strip_tags($pass2);
$website = strip_tags($website);
$facebook = strip_tags($facebook);
$myspace = strip_tags($myspace);
$bio = strip_tags($bio);
// Connect to database
include_once "Scripts/connect_to_mysql.php";
$emailCHecker = mysql_real_escape_string($email1);
$emailCHecker = eregi_replace("`", "", $emailCHecker);
// Database duplicate e-mail check setup for use below in the error handling if else conditionals
$sql_email_check = mysql_query("SELECT email FROM ptdata WHERE email='$emailCHecker'");
$email_check = mysql_num_rows($sql_email_check);
// Error handling for missing data
if ((!$firstname) || (!$surname) || (!$gender) || (!$email1) || (!$email2) || (!$pass1) || (!$pass2)) {
$errorMsg = 'ERROR: You did not submit the following required information:<br /><br />';
if(!$firstname){
$errorMsg .= ' * First Name<br />';
}
if(!$surname){
$errorMsg .= ' * Last Name<br />';
}
if(!$gender){
$errorMsg .= ' * Gender<br />';
}
if(!$email1){
$errorMsg .= ' * Email Address<br />';
}
if(!$email2){
$errorMsg .= ' * Confirm Email Address<br />';
}
if(!$pass1){
$errorMsg .= ' * Login Password<br />';
}
if(!$pass2){
$errorMsg .= ' * Confirm Login Password<br />';
}
} else if ($email1 != $email2) {
$errorMsg = 'ERROR: Your Email fields below do not match<br />';
} else if ($pass1 != $pass2) {
$errorMsg = 'ERROR: Your Password fields below do not match<br />';
} else if ($humancheck != "") {
$errorMsg = 'ERROR: The Human Check field must be cleared to be sure you are human<br />';
} else if ($email_check > 0){
$errorMsg = "<u>ERROR:</u><br />Your Email address is already in use inside our database. Please use another.<br />";
} else { // Error handling is ended, process the data and add member to database
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$firstname = mysql_real_escape_string($firstname);
$surname = mysql_real_escape_string($surname);
$email1 = mysql_real_escape_string($email1);
$pass1 = mysql_real_escape_string($pass1);
$website = mysql_real_escape_string($website);
$facebook = mysql_real_escape_string($facebook);
$myspace = mysql_real_escape_string($myspace);
$bio = mysql_real_escape_string($bio);
$venue = mysql_real_escape_string($venue);
$special = mysql_real_escape_string($special);
$firstname = eregi_replace("`", "", $firstname);
$surname = eregi_replace("`", "", $surname);
$email1 = eregi_replace("`", "", $email1);
$pass1 = eregi_replace("`", "", $pass1);
$website = eregi_replace("`", "", $website);
$facebook = eregi_replace("`", "", $facebook);
$myspace = eregi_replace("`", "", $myspace);
$bio = eregi_replace("`", "", $bio);
$location = eregi_replace("`", "", $location);
$venue = eregi_replace("`", "", $venue);
$special = eregi_replace("`", "", $special);
$website = eregi_replace("http://", "", $website);
$facebook = eregi_replace("http://", "", $facebook);
$myspace = eregi_replace("http://", "", $myspace);
// Add MD5 Hash to the password variable
$db_password = md5($pass1);
// Add user info into the database table for the main site table(audiopeeps.com)
$sql = mysql_query("INSERT INTO ptdata (firstname, surname, gender, email, password, sign_up_date, website, facebook, myspace, bio, location, venue, special)
VALUES('$firstname','$surname','$gender','$email1','$db_password', now(),'$website','$facebook','$myspace','$bio','$location','$venue','$special')")
or die (mysql_error());
$id = mysql_insert_id();
// Create directory(folder) to hold each user's files(pics, MP3s, etc.)
mkdir("PTMembers/$id", 0755);
//!!!!!!!!!!!!!!!!!!!!!!!!! Email User the activation link !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$to = "$email1";
$from = "example@example.com";
$subject = "Complete your PT Search registration as a personal trainer";
//Begin HTML Email Message
$message = "Hi $firstname,
Complete this step to activate your login identity at PTSearch.co.uk.
Click the line below to activate when ready.
http://www.ptsearch.co.uk/activation.php?id=$id&sequence=$db_password
If the URL above is not an active link, please copy and paste it into your browser address bar
Login after successful activation using your:
E-mail Address: $email1
Password: $pass1
See you on the site!
example@example.com";
//end of message
$headers = "From: $from\r\n";
$headers .= "Content-type: text\r\n";
mail($to, $subject, $message, $headers);
$msgToUser = "<h2>One Last Step - Activate through Email</h2><h4>OK $firstname, one last step to verify your email identity:</h4><br />
In a moment you will be sent an Activation link to your email address.<br /><br />
<br />
<strong><font color=\"#990000\">VERY IMPORTANT:</font></strong>
If you check your email with your host providers default email application, there may be issues with seeing the email contents. If this happens to you and you cannot read the message to activate, download the file and open using a text editor. If you still cannot see the activation link, contact site admin and briefly discuss the issue.<br /><br />
";
include_once 'ptsuccessfullreg.php';
exit();
} // Close else after duplication checks
} else { // if the form is not posted with variables, place default empty variables
$errorMsg = "Fields marked with an [ * ] are required";
$firstname = "";
$surname = "";
$gender = "";
$email1 = "";
$email2 = "";
$pass1 = "";
$pass2 = "";
}
?>
<td align="right" class="alignRt">Training Locations Covered:</td>
<td colspan="2">
<select name="location" size="7" id="location" multiple="multiple"><option value="<?php print "$location"; ?>"><?php print "$location"; ?></option>
<OPTION VALUE='London'>London</OPTION>
<OPTION VALUE='Manchester'>Manchester</OPTION>
<OPTION VALUE='Newcastle'>Newcastle</OPTION>
<OPTION VALUE='Glasgow'>Glasgow</OPTION>