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>
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);?>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?