Page 1 of 1

Modify values selected from a select field.

Posted: Fri Aug 18, 2017 6:38 am
by alex74
Hi guys,
the function I would develop is to modify a brand name that can be selected in a select field.
I already implemented the while cycle to list all the brands available fetched from an array containing a query result:

Code: Select all

<label>Brands List</label>
<select name='brands-list'>
<?php 
while ($listabrand=mysqli_fetch_array($brands)){
echo '<option value='.$listabrand['0'].'>'.$listabrand['0'].' - '.$listabrand['1'].'</option>';
}?></select>
An additional field was added in order to display the selected brand's name and change it.

Code: Select all

<label>Brand name to modify</label>
<input type="text" name='brand-name'">

The query to update the brand's name captured from 'brand-name' field is this:

Code: Select all

<?php require '../sys/conn.php';

$mod_id    = $_POST['brands-list'];
$mod_brand = $_POST['brand-name'];

if (isset(   $_POST['modify-btn'])){
$brand_id =  intval ($conn, $mod_id);
$brand    =  mysqli_real_escape_string ($conn, $mod_brand);

if ($mod_brand !=''){
$update = mysqli_query($conn,"

UPDATE mg_terms SET name= '$brand' WHERE term_id='$brand_id'");

header('Location: ../pages/success.html');      }
else{header('Location: ../pages/error.html');	}}
mysqli_close($conn);?>
What I am missing now is
a. to display in the 'brand-name' field the value selected in the select field "brands list" ;
b. update the db with modified brand's name.

Submitting the modifications the php file gives this error

Code: Select all

Notice: Undefined index: brands-list in /Applications/XAMPP/xamppfiles/htdocs/gest/php/update_brand.php on line 4
Notice: Undefined index: brand-name in /Applications/XAMPP/xamppfiles/htdocs/gest/php/update_brand.php on line 5 


Any help how to approach this issue?

Re: Modify values selected from a select field.

Posted: Wed Aug 23, 2017 5:54 pm
by Christopher
Are you sure your <select> is being built correctly? Have you viewed source to see what <option>s are being generated? I think it should be:

Code: Select all

echo '<option value='.$listabrand[0].'>'.$listabrand[0].' - '.$listabrand[1].'</option>';