Alex Alex - 5 months ago 29
SQL Question

Display value in a dedicated field selected from a list

in a php form I have the list of brands scrollable from a select field and I would modify the selected brand displaying it in a field beside.

The php form is this:

include '../sys/conn.php';
$brands = mysqli_query ($conn, "
*(query to select brands name and id)*
") or die ("Query not valid: " . mysqli_error($conn));
<form role="form" >
<label>Brands List</label>
<select class="form-control" name='brands list'>
<?php while ($listabrand=mysqli_fetch_array($brands)){
echo '<option>'.$listabrand['0'].' - '.$listabrand['1'].'</option>';
<label>Modify Brand</label>
<input type="text" name='brand-name' class="form-control" required placeholder="Brand Name to modify">

Basically I need to select the brand's name from the named "brands list" field and display it into the 'brand-name' in order to modify and save it.

Any help?

Answer Source

This is the right code.

<select class="form-control" name='brands-list'>
        while ($listabrand=mysqli_fetch_array($brands)){
        echo '<option value="'.$listabrand['1'].'">'.$listabrand['0'].' - '.$listabrand['1'].'</option>';

<div class="col-lg-8">
    <form role="form">
        <div class="form-group">
            <input type="text" name='brand-name' class="form-control">

        var selectedBrand = $(this).val();