PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Oct 22, 2018 4:13 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Fri Aug 18, 2017 6:38 am 
Offline
Forum Newbie

Joined: Fri Aug 18, 2017 3:45 am
Posts: 1
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:

Syntax: [ Download ] [ Hide ]
<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.

Syntax: [ Download ] [ Hide ]
<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:

Syntax: [ Download ] [ Hide ]
<?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

Syntax: [ Download ] [ Hide ]
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?


Top
 Profile  
 
PostPosted: Wed Aug 23, 2017 5:54 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13581
Location: New York, NY, US
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:
Syntax: [ Download ] [ Hide ]
echo '<option value='.$listabrand[0].'>'.$listabrand[0].' - '.$listabrand[1].'</option>';
 

_________________
(#10850)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Exabot [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group