Modify values selected from a select field.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alex74
Forum Newbie
Posts: 1
Joined: Fri Aug 18, 2017 3:45 am

Modify values selected from a select field.

Post 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?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Modify values selected from a select field.

Post 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>';
(#10850)
Post Reply