PHP Login System with Admin Features

This forum was created to talk about the PHP Login System with admin features created by jpmaster77 on evolt's website


    multiple field choices?

    Share
    avatar
    intothefantasy

    Number of posts : 37
    Registration date : 2009-04-11

    multiple field choices?

    Post  intothefantasy on Wed Apr 22, 2009 5:03 am

    i saw there is a radio box check tutorials....but currently i wanted to make a field which can input more than 1 values....

    like something abt

    What do you like to eat? can choose more than 1,
    so below here have multibox to be check...and all the information will be keyed in to the database..
    avatar
    Linchpin311

    Number of posts : 220
    Age : 32
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: multiple field choices?

    Post  Linchpin311 on Wed Apr 22, 2009 8:17 pm

    so im thinking you might have two options for this... you can use multiple checkboxes all that have the same name (something like name="foods[]". you need the brackets so php will put multiple selected values in an array) and different values for your food choices.

    or you can do a multiple select drop down (like <select name="foods[]" multiple="multiple">) and put your food types inside of <option> tags.

    either way, php will put multiple selected values in an array inside the $_POST['foods'] array. from there you are free to manipulate the data the same way you would with any other form variable. if you want to visibly see how your arrays are set up, try either one of these methods and submit. then wherever you submitted the data to try the vardump() function. in this case you would type vardump($_POST['foods']) to see all information about the $_POST['foods'] variable.

    hope this helps! let me know if i've lost you.


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    intothefantasy

    Number of posts : 37
    Registration date : 2009-04-11

    Re: multiple field choices?

    Post  intothefantasy on Thu Apr 23, 2009 5:22 am

    ok i am abit lost lol....can u use this part of code as example?

    http://jpmaster77forum.conceptbb.com/php-login-system-101-f2/adding-radio-buttons-t46.htm

    do i need to do anything at mysql table? basically....how u add this kind of option?
    avatar
    Linchpin311

    Number of posts : 220
    Age : 32
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: multiple field choices?

    Post  Linchpin311 on Thu Apr 23, 2009 6:49 pm

    we really dont have any tutorials on how to do this just yet... i have really been meaning to create some (really, i have!) but with the economy in the states going down hill i have been pumping as much time as i can into my 2 jobs.

    i can help you create something like this if you wish. just let me know how you wanted to display it (multiple drop down box, or multiple check boxes) and give me a few days to create something. ive got a couple projects on my plate, aside from my work obligations, so im going to have to ask for just a little of your patience. Smile


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    intothefantasy

    Number of posts : 37
    Registration date : 2009-04-11

    Re: multiple field choices?

    Post  intothefantasy on Fri Apr 24, 2009 5:37 am

    alrite sure i can wait...if is possible to make both? multiple check box and multiple drop box together? i am ma using this system for a charity use for a admin system for a association...they have a part in their register form which need to tick on multiple choices then store in db...
    avatar
    Linchpin311

    Number of posts : 220
    Age : 32
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: multiple field choices?

    Post  Linchpin311 on Mon Apr 27, 2009 4:23 pm

    hey im sorry it took me FOREVER to get back to you, but you know sometimes life just gets in the way... but hey i think i have something you'll be interested in. plug the following into your text editor and save it to your server. try it out, study the code and tell me what you think!

    Code:
    <html><body>

    <?php

    if(isset($_POST['submit'])){

       echo '<pre>';
       echo 'Displaying var_dump($_POST[\'foods\'])<br>';
       echo '<b>';
       var_dump($_POST['foods']);
       echo '</b>';
       echo '</pre>';
       
       $foods = implode($_POST['foods'],',');
       echo 'put the foods you like in the database as a varchar like this:<br>';
       echo '<b>'.$foods.'</b></p>';
       
       $foods = str_replace(',','<br>',$foods);
       echo 'You like the following fruits:<br><b>'.$foods.'</b>';
       
       echo '</p>';
       echo '---------------------------------------------------';
       echo '</p>';
       echo '<b>Try it again</b></p>';

    }

    ?>

       <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST">
       
          Select all the fruits you like<br>Use "Ctrl" to select multiple fruits<br>
          <select name="foods[]" multiple="multiple">

             <option value="apples">Apples</option>
             <option value="oranges">Oranges</option>
             <option value="bananas">Bananas</option>
             <option value="apricots">Apricots</option>
             <option value="passion_fruit">Passion Fruit</option>

          </select>
          </p>
          
          <input type="submit" name="submit" value="submit">
       
       </form>
       </p><br>
       
       <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST">
       
          Select all the fruits you like, check all that apply.<br>
          <input type="checkbox" name="foods[]" value="apples"> << Apples<br>
          <input type="checkbox" name="foods[]" value="oranges"> << Oranges<br>
          <input type="checkbox" name="foods[]" value="bananas"> << Bananas<br>
          <input type="checkbox" name="foods[]" value="apricots"> << Apricots<br>
          <input type="checkbox" name="foods[]" value="passion_fruit"> << Passion Fruit<br>
          </p>
          
          <input type="submit" name="submit" value="submit">
       
       </form>

    </body></html>


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    intothefantasy

    Number of posts : 37
    Registration date : 2009-04-11

    Re: multiple field choices?

    Post  intothefantasy on Tue Apr 28, 2009 4:50 am

    wat kind of column do i need to create in my db? i wanna ask is it 1 column can handle more than 1 values? like the food column have banana,apple like this? i wanted to make another new table which category for food but i dont know how to link them up with the main db....
    avatar
    Linchpin311

    Number of posts : 220
    Age : 32
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: multiple field choices?

    Post  Linchpin311 on Wed Apr 29, 2009 4:59 pm

    you should be ok with a varchar if there isnt going to be like 10,000 different things going in there. it should be good cause you are entering each value separated with a comma (see the implode() function). then when you retrieve the data you can use the explode() function or str_replace() function to change the commas into whatever.

    explain to me a little more what you are trying to accomplish with this category for food table. maybe i can help you out some more.


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    intothefantasy

    Number of posts : 37
    Registration date : 2009-04-11

    Re: multiple field choices?

    Post  intothefantasy on Thu Apr 30, 2009 5:20 am

    ok actually this multiple choice code will be together with my multiple query code..

    basically i have end up to design a client register page...where only admin can add user into the database based on the form which have to be filled in by the client and send to the admin for register...

    partly the form is very big...and not only that i do think i have to break up into few tables to categories them like something they can choose more than 1 value...

    etc...your fav food (this is an example)

    the form need to be tick must be in multiple choice / drop down...which then i have to enter those data into a table name FOOD where it maybe have foodid, clientid, foodname column...

    so now i need to know how do i create a multiple choice/drop down form to interact with the database and php to input those answer into the database...make radio box and drop down menu has been covered up in the tutorial section which helps me alot...

    but still i need to know how to create multiple choice now...
    avatar
    Linchpin311

    Number of posts : 220
    Age : 32
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: multiple field choices?

    Post  Linchpin311 on Thu Apr 30, 2009 10:28 pm

    i am confused. did you look at the code i posted above? it has everything you need to create a multiple selection drop down menu, or a multiple selection check box. is this not what you are looking for?


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    intothefantasy

    Number of posts : 37
    Registration date : 2009-04-11

    Re: multiple field choices?

    Post  intothefantasy on Fri May 01, 2009 1:06 am

    this is wat i get when i directly paste ur code and view it with firefox

    avatar
    Linchpin311

    Number of posts : 220
    Age : 32
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: multiple field choices?

    Post  Linchpin311 on Fri May 01, 2009 1:16 am

    what are you saving it as? it is a PHP file so you need to put the PHP extension at the end of the file if you arent already. if you are and its still displaying like that then your server isnt set up to display PHP scripts.

    that script is just an example of how to accomplish what you want. all you need to do is create a query and save the $foods variable in your database. let me know if you are still confused on this.


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    intothefantasy

    Number of posts : 37
    Registration date : 2009-04-11

    Re: multiple field choices?

    Post  intothefantasy on Fri May 01, 2009 1:30 am

    hmm ok i get wat u mean...but is it this 1 will store more than 1 value in a column in database?

    is like FOOD column the row will have like apple,orange?

    if so is there anyway to split them up into 2 rows?

    like
    ------------------------------------
    FOOD | ClientID | FoodID |
    ------------------------------------
    apple | 1 | 1 |
    ------------------------------------
    orange| 1 | 2 |
    ------------------------------------


    instead of
    -------------------------------------------
    FOOD | ClientID | FoodID |
    -------------------------------------------
    apple,orange | 1 | 1 |
    -------------------------------------------
    avatar
    intothefantasy

    Number of posts : 37
    Registration date : 2009-04-11

    Re: multiple field choices?

    Post  intothefantasy on Fri May 01, 2009 1:46 am

    and btw i know how your code works...but still i am abit confuese in implementing them inside this login system as i saw tutorials from the tuts section showing how to add custom fields like check box and multiple dropbox....they require to edit other files like process.php etc...which is y i am not sure where should i begin...
    avatar
    Linchpin311

    Number of posts : 220
    Age : 32
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: multiple field choices?

    Post  Linchpin311 on Sun May 03, 2009 11:32 pm

    well first off, depending on what you are using (check boxes or multiple drop down) you should still be following the tutorial. all the basic editing in process.php and session.php is the same. the only difference here is how you process the information.
    intothefantasy wrote:...if so is there anyway to split them up into 2 rows?
    sure, it would involve running a separate query for each food somewhere in session.php. you should count the $_POST['foods'] array so you know how many queries to run, then maybe run a for loop to insert each one.


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    intothefantasy

    Number of posts : 37
    Registration date : 2009-04-11

    Re: multiple field choices?

    Post  intothefantasy on Mon May 04, 2009 4:01 am

    do u got any sample on how to do the for loop?
    avatar
    Linchpin311

    Number of posts : 220
    Age : 32
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: multiple field choices?

    Post  Linchpin311 on Mon May 04, 2009 10:27 pm

    well once you count the $_POST['foods'] array put that in a variable (lets call it $num). then the for loop would be something like:
    Code:
    for($i = 0; $i < $num; $i++){

        $q = "INSERT INTO `foods` (`FOOD`, `ClientID`, `FoodID`) VALUES ('" . $_POST['foods'][$i] . "', '$ClientID', '$FoodID')";
        mysql_query($q);

    }

    this should step through all the values of the $_POST['foods'] array and stop when the array has no more values. of course you may have to edit $ClientID and $FoodID to fit your needs, but this should get you started in the right direction.


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    intothefantasy

    Number of posts : 37
    Registration date : 2009-04-11

    Re: multiple field choices?

    Post  intothefantasy on Tue May 05, 2009 2:56 am

    hmm i think i get wat u are talking abt but there is still 1 part i am abit confuese

    you should count the $_POST['foods'] array

    i not sure how to count the $_POST['foods'] array....if i can settle this out i think i could start out testing

    is it something like this?

    Code:
    print count($food) = $num;
    avatar
    intothefantasy

    Number of posts : 37
    Registration date : 2009-04-11

    Re: multiple field choices?

    Post  intothefantasy on Tue May 05, 2009 5:19 am

    ok seems i try it out and i having problems inserting the value into my database...i try with a simple insert code without using php login system insert...no errors but it dosent insert anything into my database....here is the code

    Code:

    <?PHP include($sessionpath); ?>
    <?PHP include($headerpath); ?>
    <?php

    include("config.php");

    if($session->isAdmin()){
      if(isset($_POST['submit']))
      {
       
        $catname = $_POST['catname'];
        $values = $_POST['values'];
         
                  if(!$catname){ 
                        echo "Error: category name is a required field. Please fill it.";
                        exit();
                  }
    $num = count($values) ;
           
            for($i = 0; $i < $num; $i++){

        $q = "INSERT INTO `cats` (`dtime`, `catname`, `values`,) VALUES ('NOW()', '$catname', '" . $_POST['values'][$i] . "')";
        mysql_query($q);

    }
                        echo "<b>Success";
      } 
    else
      {

          ?>
     
        <table border="0" cellpadding="0" cellspacing="0" width="100%">
                    <tr>
                      <td width="100%" valign="top" class="content_text">
                      <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST">
       
          catname: <input name="catname" size="40" maxlength="255"><br />
          Select all the fruits you like, check all that apply.<br>
          <input type="checkbox" name="values[]" value="apples"> << Apples<br>
          <input type="checkbox" name="values[]" value="oranges"> << Oranges<br>
          <input type="checkbox" name="values[]" value="bananas"> << Bananas<br>
          <input type="checkbox" name="values[]" value="apricots"> << Apricots<br>
          <input type="checkbox" name="values[]" value="passion_fruit"> << Passion Fruit<br>
          </p>
         
          <input type="submit" name="submit" value="submit">
     
      </form>
                      </td>
                    </tr>
                  </table>
                  </div>
            <br />
          <?
      }//end of else
     
     }
     else{
     echo "Only authorize personal can access to this page";
     }
    ?>

    <?PHP include($footerpath); ?>
    avatar
    intothefantasy

    Number of posts : 37
    Registration date : 2009-04-11

    Re: multiple field choices?

    Post  intothefantasy on Fri May 08, 2009 4:58 am

    hmm no one could help me out with the codes above?
    avatar
    Linchpin311

    Number of posts : 220
    Age : 32
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: multiple field choices?

    Post  Linchpin311 on Fri May 08, 2009 10:37 pm

    sorry, i must have lost this thread for a sec...

    no errors, huh? i looked at your code quick and i dont see anything that looks out of place. on the line where you submit your query, mysql_query($q);... try adding a die() to that so it looks something like mysql_query($q) or die(mysql_error());. let me know if you still dont get any errors.


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    intothefantasy

    Number of posts : 37
    Registration date : 2009-04-11

    Re: multiple field choices?

    Post  intothefantasy on Fri May 08, 2009 11:09 pm

    yea now i got this kinda errors

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') VALUES ('NOW()', 'aaaa', 'apples')' at line 1
    avatar
    Linchpin311

    Number of posts : 220
    Age : 32
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: multiple field choices?

    Post  Linchpin311 on Fri May 08, 2009 11:25 pm

    NOW() shouldnt be in quotes. could that be the problem?


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    intothefantasy

    Number of posts : 37
    Registration date : 2009-04-11

    Re: multiple field choices?

    Post  intothefantasy on Fri May 08, 2009 11:25 pm

    tried that i still get the same error just minus the quotes
    avatar
    Linchpin311

    Number of posts : 220
    Age : 32
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: multiple field choices?

    Post  Linchpin311 on Fri May 08, 2009 11:27 pm

    post your query here so we can take a look at it.


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.

    Sponsored content

    Re: multiple field choices?

    Post  Sponsored content


      Current date/time is Mon Dec 11, 2017 7:00 pm