1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Update some records of table

Discussion in 'PHP' started by piropeator, Jul 30, 2016.

  1. #1
    Hi guys.
    I have this form.
    Show records, checkbox, code and name, but name can be changed.
    I want to change some records but only if it had checked first.
    <form name="cambio_nombre" class="" action="index.php?action=subirCargos4" method="POST" enctype="multipart/form-data">
        <table id="miTabla" class="table table-striped table-bordered table-hover table-condensed">
            <tr id="cabecera" class="active">
                <th>Update</th>
                <th>Code</th>
                <th>Name in Master</th>
                <th>New Name</th>
            </tr>
            {section name=i loop=$lista}
            <tr class="success">
                <td><input type="checkbox" name="codigo[]" id="codigo" value="{$lista[i]->codigo}"></td>
                <td>{$lista[i]->codigo}</td>
                <td>{$lista[i]->nombre_old}</td>
                <td><input type="text" name="nombre" id="nombre" value="{$lista[i]->nom_new}"></td>
            </tr>
            {/section}
        </table>
    
        <div class="modal-footer">
            <button class="btn btn-primary">Procesar</button>
        </div>
    </form>
    
    HTML:
    For example: First:
    chk code name
    [ ] 100 paolo
    [ ] 200 pedro
    [ ] 300 rose
    [ ] 400 sean

    checked:
    chk code name
    [x] 100 linda
    [ ] 200 pedro
    [x] 300 frank
    [ ] 400 sean

    When I push a button, php file receive an array to update that records.
    What need to change in my form to get that?
     
    piropeator, Jul 30, 2016 IP
  2. gummyworms

    gummyworms Active Member

    Messages:
    126
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #2
     $codigo = $_POST['codigo'];
    Code (markup):
    in the php The $indigo will automatically be an array
    You can even do it print_r command to check it
     
    gummyworms, Jul 30, 2016 IP
  3. piropeator

    piropeator Well-Known Member

    Messages:
    194
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    121
    #3
    In the view
    <input type="text" name="nombre" id="nombre" value="{$lista[i]->nom_new}">
    HTML:
    I can to change the NAME.
    But
    codigo[]
    HTML:
    pass only the codes.
    If I use
    nombre[]
    HTML:
    In php file receive:
    codigo[] only codes checked, but nombre[] get all nombres in list. And I need only nombre[] was checked.
     
    piropeator, Aug 1, 2016 IP
  4. gummyworms

    gummyworms Active Member

    Messages:
    126
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #4
    <td><input type="text" name="nombre" id="nombre" value="{$lista[i]->nom_new}"></td>
    Code (markup):
    you have nombre as type = "text", it should be "checkbox" right?
     
    gummyworms, Aug 1, 2016 IP
  5. piropeator

    piropeator Well-Known Member

    Messages:
    194
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    121
    #5
    There are a checkbox, get the code, but I want it gets to get nombre too.
     
    piropeator, Aug 2, 2016 IP