#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2017
    Location
    ITALY
    Posts
    14
    Rep Power
    0

    Capturing the ID stored in an array from a select field


    In a select field i have stored three different values of an array .
    The $listabrand['0'] contains the ID of the record.

    PHP Code:
    <select name='brands_list'>
        <option value="0">Select the Brand</option>
        <?php 
        
    while ($listabrand=mysqli_fetch_array($brands)){
        echo 
    '<option value="'.$listabrand['0'].','.$listabrand['1'].','.$listabrand['2'].'"> 
            '
    .$listabrand['1'].'</option>';
         }
    ?>
        </select>
    I am implementing the DELETE Record function, selecting the value in the field 'brands_list' but at point it's difficult to me declare the ID into a variable since the brands_list field contains 3 different array values.

    I put this but of course can't work because it doesn't know which value have to capture and it should be the $listabrand['0'].

    PHP Code:
     $mod_id mysqli_real_escape_string ($conn$_REQUEST['brands_list']); 
    I embed the full php, may it could be helpful

    PHP Code:
    <?php
        
    require '../sys/conn.php';
        
    $mod_id mysqli_real_escape_string ($conn$_REQUEST['brands_list']);
        if (isset(
    $_GET['delete_brand'])){
            
    $delquery  mysqli_query($conn,"DELETE FROM mg_terms where term_id= $mod_id");
            
    $delquery1 mysqli_query($conn,"DELETE FROM mg_term_taxonomy where term_id= $mod_id");
            
    $delquery2 mysqli_query($conn,"DELETE FROM mg_termmeta where term_id= $mod_id");
        
    header('Location: ../pages/success.html');
        }
        else{
    header('Location: ../pages/error.html');
        }
        
    mysqli_close($conn);
        
    ?>
    The question is, how to select the ID in the above condition. Suggestions?
  2. #2
  3. Lord of the Dance
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Oct 2003
    Posts
    4,128
    Rep Power
    2010
    If you send a comma-seperated value, you will have to split it when you receive it.
    Something like this:
    PHP Code:
        $mod_id mysqli_real_escape_string ($conn$_REQUEST['brands_list']);
        
    $mod_id_array explode(","$mod_id);
        if (isset(
    $_GET['delete_brand'])){
            
    $delquery  mysqli_query($conn,"DELETE FROM mg_terms where term_id = $mod_id_array[0]");
            
    $delquery1 mysqli_query($conn,"DELETE FROM mg_term_taxonomy where term_id = $mod_id_array[1]");
            
    $delquery2 mysqli_query($conn,"DELETE FROM mg_termmeta where term_id = $mod_id_array[2]");
        
    header('Location: ../pages/success.html');
        } 
  4. #3
  5. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,333
    Rep Power
    9645
    Suggestion: don't put multiple values into the same form field. Why do you even need three of them at once?
  6. #4
  7. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,780
    Rep Power
    4536
    explode() will get you what you want, but this is a bad implementation.

    Pass the value you want and the other values in hidden fields, if you need them.

    John
    -- Cigars, whiskey and wild, wild women. --
  8. #5
  9. Lord of the Dance
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Oct 2003
    Posts
    4,128
    Rep Power
    2010
    Originally Posted by Sepodati
    Pass the value you want and the other values in hidden fields, if you need them.

    John
    Will you have 2-3 hidden rows for each possible selection on the list?

    From what I can see, only the value in $listabrand['1'] should be needed for the list (value and display text).
    When user do a submit, then the other values can be retrieved based on that selection.
  10. #6
  11. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,780
    Rep Power
    4536
    Originally Posted by MrFujin
    Will you have 2-3 hidden rows for each possible selection on the list?

    From what I can see, only the value in $listabrand['1'] should be needed for the list (value and display text).
    When user do a submit, then the other values can be retrieved based on that selection.
    "if you need them" but yes, you're right.
    -- Cigars, whiskey and wild, wild women. --

IMN logo majestic logo threadwatch logo seochat tools logo