Multi select list php code help

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

'; if(!$firstname){ $errorMsg .= ' * First Name
'; } if(!$surname){ $errorMsg .= ' * Last Name
'; } if(!$gender){ $errorMsg .= ' * Gender
'; } if(!$email1){ $errorMsg .= ' * Email Address
'; } if(!$email2){ $errorMsg .= ' * Confirm Email Address
'; } if(!$pass1){ $errorMsg .= ' * Login Password
'; } if(!$pass2){ $errorMsg .= ' * Confirm Login Password
'; } } else if ($email1 != $email2) { $errorMsg = 'ERROR: Your Email fields below do not match
'; } else if ($pass1 != $pass2) { $errorMsg = 'ERROR: Your Password fields below do not match
'; } else if ($humancheck != "") { $errorMsg = 'ERROR: The Human Check field must be cleared to be sure you are human
'; } else if ($email_check > 0){ $errorMsg = "ERROR:
Your Email address is already in use inside our database. Please use another.
"; } 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 = "[email protected]"; $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! [email protected]"; //end of message $headers = "From: $from\r\n"; $headers .= "Content-type: text\r\n"; mail($to, $subject, $message, $headers); $msgToUser = "

One Last Step - Activate through Email

OK $firstname, one last step to verify your email identity:


In a moment you will be sent an Activation link to your email address.


VERY IMPORTANT: 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.

"; 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 = ""; } ?> PT Search | The Personal Trainer Search Network | Gym Search Network
  • Home
  • Search For
    	</ul>
    </li>
    <li>
    	<a href="#">Register As</a>
    	<ul>
    		<li><a href="ptregister.php">Personal Trainer</a></li>
    		<li><a href="gymregister.php">Gym</a></li>
    	</ul>
    </li>
    <li>
    	<a href="#">Login As</a>
    	<ul>
    		<li><a href="ptlogin.php">Personal Trainer</a></li>
    		<li><a href="gymlogin.php">Gym</a></li>
    	</ul>
    </li>
    <li>
    	<a href="#">Health Tips</a>
    	<ul>
    		<li><a href="nutrition.php">Nutrition</a></li>
    		<li><a href="exercises.php">Exercises</a></li>
            <li><a href="helplinks.php">Helpful Links</a></li>
    	</ul>
    </li>
    <li>
    	<a href="#">PT Career</a>
    	<ul>
    		<li><a href="advice.php">PT Advice</a></li>
    		<li><a href="courses.php">Courses</a></li>
            <li><a href="business.php">Business Setup</a></li>
            <li><a href="legal.php">Legal Stuff</a></li>
            <li><a href="Equipment.php">Equipment</a></li>
    	</ul>
    </li>
    <li><a href="contact.php">Contact</a></li>
    

Personal Trainer Signup Page

Please Do First →
Add [email protected] to your email white list or safe sender list now, or else you might not get the activation email that is necessary for logging in successfully.
<?php print "$errorMsg"; ?>
First Name: * " size="32" maxlength="20" />
Surname: * " size="32" maxlength="20" />
Gender: * Male Female
E-mail Address: * " size="32" maxlength="48" />
        </td>
      </tr>
      <tr>
        <td align="right" class="alignRt">Confirm E-mail Address: <span class="brightRed">*</span></td>
        <td colspan="2">
        <input name="email2" type="text" class="formFields" id="email2" value="<?php print "$email2"; ?>" size="32" maxlength="48" />
        
        
        </td>
      </tr>
      <tr>
        <td align="right" class="alignRt">Create Password:<span class="brightRed"> *</span></td>
        <td colspan="2"><input name="pass1" type="password" class="formFields" id="pass1" maxlength="16" />
          <span class="textSize_9px"><span class="greyColor">Alphanumeric Characters Only</span></span></td>
      </tr>
      <tr>
        <td align="right" class="alignRt">Confirm Password:<span class="brightRed"> *</span></td>
        <td colspan="2"><input name="pass2" type="password" class="formFields" id="pass2" maxlength="16" />
        <span class="textSize_9px"><span class="greyColor">Alphanumeric Characters Only</span></span></td>
      </tr>
     
     
      <tr>
        <td align="right" class="alignRt">Website URL:</td>
        <td colspan="2"><strong>http://</strong>
        <input name="website" type="text" class="formFields" id="website" value="<?php print "$website"; ?>" size="40" maxlength="88" /></td>
      </tr>
      <tr>
      <tr>
        <td align="right" class="alignRt">Facebook URL:</td>
        <td colspan="2"><strong>http://</strong>
        <input name="website" type="text" class="formFields" id="facebook" value="<?php print "$facebook"; ?>" size="40" maxlength="88" /></td>
      </tr>
      <tr>
      <tr>
        <td align="right" class="alignRt">Myspace URL:</td>
        <td colspan="2"><strong>http://</strong>
        <input name="website" type="text" class="formFields" id="myspace" value="<?php print "$myspace"; ?>" size="40" maxlength="88" /></td>
      </tr>
      <tr>
      
      <tr>
        <td align="right" class="alignRt">&nbsp;</td>
        <td colspan="2">
        <tr>
        <td align="right" class="alignRt">&nbsp;</td>
        <td colspan="2">
		<tr>
        <td align="right" class="alignRt">Introduction Biography:</td>
        <td colspan="2">
        <textarea name="bio" cols="50" id="bio" rows="8" value="<?php print "$bio"; ?>" maxlength="500" /></textarea>                   
        </td>
      </tr>
      <tr>
        <td align="right" class="alignRt"></td>
        <td colspan="2">              
        </td>
      </tr>
      <tr>
        <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>
        
        
        </select>                   
        </td>
      </tr>
      <tr>
        <td align="right" class="alignRt"></td>
        <td colspan="2">              
        </td>
      </tr>
      <tr>
        <td align="right" class="alignRt">Training Venues Covered:</td>
        <td colspan="2">
        <select name="venue" size="7" value="<?php print "$venue"; ?>" id="venue" multiple>
        <OPTION VALUE>Your Home</OPTION>
        <OPTION VALUE>My Home</OPTION>
        <OPTION VALUE>Outside</OPTION>
        <OPTION VALUE>Your Work</OPTION>
        <OPTION VALUE>Private Studio</OPTION>
        <OPTION VALUE>Gym</OPTION>
        
        
        </select>                   
        </td>
      </tr>
       <tr>
        <td align="right" class="alignRt">Training Specialities:</td>
        <td colspan="2">
        <select name="special" size="7" value="<?php print "$special"; ?>" id="special" multiple>
        <OPTION VALUE>Body Building</OPTION>
        <OPTION VALUE>Marathon Training</OPTION>
        <OPTION VALUE>Iron Man Training</OPTION>
        <OPTION VALUE>Weightloss</OPTION>
        <OPTION VALUE>Muscle Gain</OPTION>
        <OPTION VALUE>Cardio</OPTION>
        
        
        </select>                   
        </td>
      </tr>
      
      <tr>
        <td align="right" class="alignRt"><br />
          Human Check: <span class="brightRed">*</span></td>
        <td colspan="2"><br />
          <input name="humancheck" type="text" class="formFields" id="humancheck" value="Please remove all of this text" size="38" maxlength="32" />
          </td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="2"><p><br />
          <input type="submit" name="Submit3" value="Register" />
        </p></td>
      </tr>
    </form>
  </table>

 

Content for id "Footer_Content" Goes Herefhsgdjkfgh

sjdfhkdsjfhsdkfjhsd

jhsdkfjdhsfkjshf

You have select options like this:

<OPTION VALUE>Your Home</OPTION>

What is the value what you post to your php script, how will you recognize selection?

Sponsor our Newsletter | Privacy Policy | Terms of Service