Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Sep 2007
    Posts
    809
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Allowing multi values to be posted

    Hi,

    I have a form which contains a list (allowing multiple values to be selected)

    i.e.

    Code:
    <select name="categories" multiple="multiple" size="7">
    <option value="Business Manager/Bursar">Business Manager/Bursar</option>
    <option value="Cover Supervisor">Cover Supervisor</option>
    <option value="Education Recruitment Consultant">Education Recruitment Consultant</option>
    <option value="Middle School">Middle School</option>
    <option value="Nursery Nurse">Nursery Nurse</option>
    <option value="Playworker">Playworker</option>
    <option value="Primary Head Teacher">Primary Head Teacher</option>
    <option value="Primary Teacher">Primary Teacher</option>
    <option value="School Support Staff">School Support Staff</option>
    <option value="Secondary Head Teacher">Secondary Head Teacher</option>
    <option value="Secondary Teacher">Secondary Teacher</option>
    <option value="SEN Teacher">SEN Teacher</option>
    <option value="Teaching Assistant &amp; HLTA">Teaching Assistant &amp; HLTA</option>
    <option value="TESOL/TEFL/EAL">TESOL/TEFL/EAL</option>
    </select>
    However it will only allow me to place one value in the database (last selected)...

    I have tried the following PHP but to no avail...

    PHP Code:
    if (is_array($categories)) {
            
    $categories implode (", " $categories);
        } 
    I have also searched these forums as I expected to be a common problem, but found no suitable results.

    Can anyone advise or kick me in the right direction.

    Many Thanks,

    Greens85

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,864
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    Sep 2007
    Posts
    809
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Following that tutorial Ive now got this code:

    PHP Code:
    $categories $_POST['categories'];
            if (
    $categories) {
                foreach (
    $catgories as $cats); {
                }
                } 
    The only change being I've omitted the echo as I want to pass it to a database which I do further down in the page..,

    Code:
    $q1 = "INSERT INTO jobseekers (regdate, uname, upass, title, fname, lname, country, zip, address, phone, categories, experience) 
     VALUES ('$EXmonth/$EXday/$EXyear', '$uname', '$upass', '$mtitle', '$fname', '$lname', '$country', '$zip', '$address', '$phone', '$cats', '$experience')";
    However I am receiving the following error:

    Warning: Invalid argument supplied for foreach() in /home/teaching/public_html/testpages/process_creg.php on line 18

    Is this because the insert statement needs to come within the foreach? e.g.


    PHP Code:
    $categories $_POST['categories'];
            if (
    $categories) {
                foreach (
    $catgories as $cats); {
     
    // "INSERT INTO jobseekers (categories) VALUES ('$cats')";
    }
                } 
    Or am I doing something else incorrect?

  • #4
    Regular Coder
    Join Date
    Sep 2007
    Posts
    809
    Thanks
    5
    Thanked 2 Times in 2 Posts
    I can get the values into the database with the following code, the problem is it adds a record for each option that was selected... so if I selected 4 options for the list, then it would add 4 records of the data i entered:

    PHP Code:
    $values $_POST['categories'];
        foreach (
    $values as $a) {

     
    $EXday date('d'mktime(0,0,0,0date(d) + 00));
     
    $EXmonth date('m'mktime(0,0,0date(m), date(d) + 00));
     
    $EXyear date('Y'mktime(0,0,0,date(m) ,date(d) + 0date(Y)));

     
    $q1 "INSERT INTO jobseekers (regdate, uname, upass, title, fname, lname, country, zip, address, phone, categories, experience) 
     VALUES ('$EXmonth/$EXday/$EXyear', '$uname', '$upass', '$mtitle', '$fname', '$lname', '$country', '$zip', '$address', '$phone', '$a', '$experience')"
    ;

     
    $r1 mysql_query($q1) or die('error'mysql_error());

     
    $q2 "select * from jobseekers where uname = \"$uname\" ";
     
    $r2 mysql_query($q2) or die(mysql_error(Error5));
     
    $a2 mysql_fetch_array($r2);

     
    $q4 "insert into resumes set
         jobseekerid = \"$a2[jobseekerid]\""
    ;

     
    $r4 mysql_query($q4) or die('error');


    Can anyone help me? I only want to have it create one record but list all values under categories in the database!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •