SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jul 2013
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multiple Select Elements

    I have been messing with this for a few days now and I have come to a dead end. I don't consider my self good at PHP coding. I have 4 "Select" elements and the names for them are sub[1] sub[2] sub[3] and sub[4]. I have a jQuery that displays the different one depending on the previous select element. In my PHP code I am trying to make it find the "sub" that the user has chosen from.

    HTML:
    PHP Code:
    <div class="input-group item">
                      <
    span class="input-group-addon">Type</span>
                          <
    select id="type" name="type" class="form-control" onclick="typefunction(); itemstats(); Armor();">
                              <
    option value="Any Type">Any Type</option>
                              <
    option value="1-Hand">1-Hand</option>
                              <
    option value="2-Hand">2-Hand</option>
                              <
    option value="Armor">Armor</option>
                              <
    option value="Off-Hand">Off-Hand</option>
                        </
    select>
                    </
    div>
                    <
    div class="input-group item">
                      <
    span class="1-Hand input-group-addon" style="display: none;">Sub-Type</span>
                        <
    select class="1-Hand form-control" name="sub[1]" style="display: none;">
                              <
    option value="All 1-Hand Item Types">All 1-Hand Item Types</option>
                              <
    option>Axe</option>
                              <
    option>Ceremonial Knife</option>
                              <
    option>Hand Crossbow</option>
                              <
    option>Dagger</option>
                              <
    option>Fist Weapon</option>
                              <
    option>Mace</option>
                              <
    option>Mighty Weapon</option>
                              <
    option>Spear</option>
                              <
    option>Sword</option>
                              <
    option>Wand</option>
                          </
    select>
                          </
    div>
                     
                     <
    div class="input-group">
                      <
    span class="2-Hand input-group-addon" style="display: none; ">Sub-Type</span>
                        <
    select class="2-Hand form-control" name="sub[2]" style="display: none;">
                              <
    option>All 2-Hand Item Types</option>
                              <
    option>Two-Handed Axe</option>
                              <
    option>Bow</option>
                              <
    option>Diabo</option>
                              <
    option>Crossbow</option>
                              <
    option>Two-Handed Mace</option>
                              <
    option>Two-Handed Mighty Weapon</option>
                              <
    option>Polearm</option>
                              <
    option>Staff</option>
                              <
    option>Two-Handed Sword</option>
                          </
    select>
                          </
    div>

                      
                      <
    div class="input-group">
                      <
    span class="Armor input-group-addon" style="display: none;">Sub-Type</span>
                        <
    select class="Armor form-control" name="sub[3]" style="display:none;">
                                <
    option>All Armor Item Types</option>
                              <
    option>Amulet</option>
                              <
    option>Belt</option>
                              <
    option>Boots</option>
                              <
    option>Bracers</option>
                              <
    option>Chest Armor</option>
                              <
    option>Cloak</option>
                              <
    option>Gloves</option>
                              <
    option>Helm</option>
                              <
    option>Pants</option>
                              <
    option>Mighty Belt</option>
                              <
    option>Ring</option>
                              <
    option>Shoulders</option>
                              <
    option>Spirit Stone</option>
                              <
    option>Voodoo Mask</option>
                              <
    option>Wizard Hat</option>
                          </
    select>
                          </
    div>
                    
                    <
    div class="input-group">
                      <
    span class="off input-group-addon" style="display: none;">Sub-Type</span>
                        <
    select class="off form-control" name="sub[4]" style="display:none;">
                              <
    option>All Off-Hand Item Types</option>
                              <
    option>Mojo</option>
                              <
    option>Source</option>
                              <
    option>Quiver</option>
                              <
    option>Shield</option>
                          </
    select>
                          </
    div
    PHP:
    PHP Code:
    $subType $_POST['sub'][1];
    $TwoHand $_POST['sub'][2];
    $Armor $_POST['sub'][3];
    if (
    $subType == 'All 1-Hand Item Types') {
        
    $Armor $subType;

    JQuery:
    PHP Code:
    function typefunction() {
        var 
    itemTypes jQuery('#type');
        var 
    select this.value;
        
    itemTypes.change(function() {
            if ($(
    this).val() == '1-Hand') {
                $(
    '.1-Hand').show();
                $(
    '.2-Hand').hide();
                $(
    '.off').hide();
                $(
    '.Armor').hide();
            }
            else $(
    '.1-Hand').hide();
            $(
    '.off').hide();
            if ($(
    this).val() == '2-Hand') {
                $(
    '.2-Hand').show();
                $(
    '.1-Hand').hide();
                $(
    '.off').hide();
                $(
    '.Armor').hide();
            }
            else $(
    '.2-Hand').hide();
            $(
    '.off').hide();
            if ($(
    this).val() == 'Armor') {
                $(
    '.Armor').show();
                $(
    '.2-Hand').hide();
                $(
    '.off').hide();
                $(
    '.1-Hand').hide();
            }
            else $(
    '.Armor').hide();
            $(
    '.off').hide();
            if ($(
    this).val() == 'Off-Hand') {
                $(
    '.off').show();
                $(
    '.2-Hand').hide();
                $(
    '.1-Hand').hide();
                $(
    '.Armor').hide();
            }
            else $(
    '.off').hide();
        });


  2. #2
    SitePoint Evangelist
    Join Date
    Oct 2005
    Location
    Michigan, USA
    Posts
    434
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    1. What are you expecting?
    2. What actually happens?
    - Robert

  3. #3
    SitePoint Member
    Join Date
    Jul 2013
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by QMonkey View Post
    1. What are you expecting?
    2. What actually happens?
    I want it to see if sub[1] == "All 1-Hand Item Types" if it does equal that then it looks to see what sub[2] is and if that == "All 2-Hand Item Types" then it moves to the third one and so on.

    It does absolutely nothing, it doesn't get to the "INSERT INTO"

  4. #4
    SitePoint Evangelist
    Join Date
    Oct 2005
    Location
    Michigan, USA
    Posts
    434
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    All of your <option> need value="something" for your $_POST['sub'][1] (and [2] and [3] and [4]) to have a value. That might be the source of the problem. Hard to tell since there isn't much PHP code posted here. Even if that isn't what's causing this issue, you're going to need those values in there so I'd say start with that and see what happens.
    - Robert

  5. #5
    SitePoint Member
    Join Date
    Jul 2013
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the entire code:

    PHP Code:
    <?php

    class Account extends MainController{
        function 
    __construct(){
                
    parent::__construct();
                if(
    $_SESSION['user'] == ""){
                    
    header("location:Logout");
                    exit(
    0);
                }else{
                    
                    
    $sql "SELECT * FROM users WHERE username = :username ";
                    
    $arr = array(":username" => $_SESSION['user']);
                    
    $ctr $this->database->DBCtr($sql,$arr);
                    
                    if(
    $ctr 0){
                        
    $usr $this->database->DBQry($sql,$arr);
                        
    $this->view->usr $usr[0]['username'];
                        
    $this->view->pss $usr[0]['password'];
                        
    $this->view->name $usr[0]['user_id'];
                    }else{
                        
    header("location:Index");
                        exit(
    0);
                    }
                    
                }
        }
        
        function 
    ChangePassword(){
            
    $this->view->url    =    $this->config->url;
            
    $this->view->ID       get_class($this);
            
    $this->view->Title "Royal JD > Account > Change Password";
            
    $this->view->render('Account/ChangePassword');
        }
        
        function 
    ChangePasswordSubmit(){
            
            
    $this->view->url    =    $this->config->url;
            
    $this->view->ID       get_class($this);
            
    $this->view->Title "Royal JD > Account > Change Password";
            
            
    $new = isset($_POST['new']) ? $_POST['new'] : '';
            
    $old = isset($_POST['old']) ? $_POST['old'] : '';
            
    $con = isset($_POST['con']) ? $_POST['con'] : '';
            
    $this->view->usr mysql_real_escape_string(StrToLower(Trim($this->view->usr)));
            
    $new mysql_real_escape_string(StrToLower(Trim($new)));

            
    $this->view->salt $usr[0]['username'];
            
    $this->view->salt $this->view->name.$new;
            
    $this->view->salt md5($this->view->salt);
            
    $this->view->salt "0x".$this->view->salt//Salts the password in md5.
            
    $this->view->msg "";
            
    $this->view->err false;
            
            if(
    $old != $this->view->pss){
                
    $this->view->msg "Old Password is Incorrect";
            }elseif(
    $new == ""){
                
    $this->view->msg "New Password is Empty";
            }elseif(
    $con != $new){
                
    $this->view->msg "Please Confirm Password Correctly";
            }else{
                
    $arr = array(":idnumber" => $new":passwd" => $this->view->salt);
                
    $this->database->DBSet($arr,'users',$whr 'WHERE ID = '.$add);
                
    $this->view->msg "Password is Successfully Changed";
                
    $this->view->err true;
            }
            
            
    $this->view->render('Account/ChangePasswordSubmit');
            
            
            
        }

        function 
    AddItem(){
            
    $this->view->url    =    $this->config->url;
            
    $this->view->ID       get_class($this);
            
    $this->view->Title "D3 > Account > Add Item";
            
    $this->view->render('Account/AddItem');
        }

        function 
    AddItemSubmit(){
            
    $this->view->url    =    $this->config->url;
            
    $this->view->ID       get_class($this);
            
    $this->view->Title "D3 > Account > Add Item";

            
    $itemName2 = isset($_POST['item_name']) ? ($_POST['item_name']) : '';
            
    $itemName mysql_escape_string($itemName2);
            
    $img = isset($_POST['img_path']) ? ($_POST['img_path']) : '';
            
    $Quality $_POST['quality'];
            
    $Type $_POST['type'];
            
    $subType $_POST['sub'][1];
            
    $TwoHand $_POST['sub'][2];
            
    $Armor $_POST['sub'][3];
            
    $itemAttrib1 $_POST['list_1'];
            
    $itemAttrib2 $_POST['list_2'];
            
    $itemAttrib3 $_POST['list_3'];
            
    $itemAttrib4 $_POST['list_4'];
            
    $itemAttrib5 $_POST['list_5'];
            
    $itemAttrib6 $_POST['list_6'];
            
    $itemAttrib7 $_POST['list_7'];
            
    $itemAttrib8 $_POST['list_8'];
            
    $Value_1 = isset($_POST['val_1']) ? ($_POST['val_1']) : '';
            
    $Value_2 = isset($_POST['val_2']) ? ($_POST['val_2']) : '';
            
    $Value_3 = isset($_POST['val_3']) ? ($_POST['val_3']) : '';
            
    $Value_4 = isset($_POST['val_4']) ? ($_POST['val_4']) : '';
            
    $Value_5 = isset($_POST['val_5']) ? ($_POST['val_5']) : '';
            
    $Value_6 = isset($_POST['val_6']) ? ($_POST['val_6']) : '';
            
    $Value_7 = isset($_POST['val_7']) ? ($_POST['val_7']) : '';
            
    $Value_8 = isset($_POST['val_8']) ? ($_POST['val_8']) : '';

            
    $sql "SELECT * FROM item_images WHERE item_name = :imgurl ";
                    
    $arr = array(":imgurl" => $itemName2);
                    
    $ctr $this->database->DBCtr($sql,$arr);
            if(
    $ctr 0){
                        
    $path $this->database->DBQry($sql,$arr);
                        
    $this->view->ipath $path[0]['item_img'];
            }

            if (
    $subType == "All 1-Hand Item Types"){
                
    $Armor $subType;
            }

            
    $ipath $this->view->ipath;

            
    $this->view->msg "";
            
    $this->view->err false;

            if (
    $itemName == ""){
                
    $this->view->msg "You must enter an item name!";
            }elseif (
    $Quality == "Any Quality"){
                
    $this->view->msg "You must choose a quality!";
            }elseif (
    $Type == "Any Type"){
                
    $this->view->msg "You must choose a type!";
            }elseif (
    $subType == "Any Subtype"){
                
    $this->view->msg "You must choose a sub type!";
            }elseif (!
    ctype_digit($Value_1)){
                
    $this->view->msg "You must enter a value";
            }else{
                
    $sql "INSERT INTO `items_us_sc` (`item_num`, `item_name`, `quality`, `type`, `sub_type`, `attrib_1`, `value_1`, `attrib_2`, `value_2`, `attrib_3`, `value_3`, `attrib_4`, `value_4`, `attrib_5`, `value_5`, `attrib_6`, `value_6`, `attrib_7`, `value_7`, `attrib_8`, `value_8`, `item_img`) VALUES (NULL, '$itemName', '$Quality', '$Type', '$subType', '$itemAttrib1', '$Value_1', '$itemAttrib2', '$Value_2', '$itemAttrib3', '$Value_3', '$itemAttrib4', '$Value_4', '$itemAttrib5', '$Value_5', '$itemAttrib6', '$Value_6', '$itemAttrib7', '$Value_7', '$itemAttrib8', '$Value_8', '$ipath')";
                
    $arr = array();
                
    $ctr $this->database->DBQry($sql,$arr);
                
    $this->view->msg $subType;
                
    $this->view->err true;
            }

            
    $this->view->render('Account/AddItemSubmit');

        }
    }
    ?>
    Last edited by Stevie D; Nov 3, 2013 at 04:00. Reason: Code tags corrected

  6. #6
    SitePoint Evangelist
    Join Date
    Oct 2005
    Location
    Michigan, USA
    Posts
    434
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You definitely need to add in those value attributes to the option tags. But what selections you make there don't affect your code.

    You need to check that you're actually getting into AddItemSubmit(). Is the form submitting at all?
    - Robert

  7. #7
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,192
    Mentioned
    17 Post(s)
    Tagged
    4 Thread(s)
    Perhaps consider using an existing plugin to achieve the chained select/linked list functionality.
    The only code I hate more than my own is everyone else's.


Bookmarks

Posting Permissions

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