as part of my project I have two files:
- modify_brand.php (php form)
- update_brand.php (script to update the DB)
In File 1. the brands are listed in a select field and displayed in a separated field that allows to modify the brand's name. The file 2. contains the query that update the DB.
The problem consists of passing the ID of the selected brand to the UPDATE query stored in update_brand.php in order to identify the record to update.
May be I am approaching the matter in a wrong way, but if not do you know how to pass to the query the ID?
modify_brand.php
<form role="form" action='../php/update_brand.php' method='post'>
<label>BRANDS LIST</label>
<select name='brands-list'>
<?php
while ($listabrand=mysqli_fetch_array($brands)){
echo '<option value="'.$listabrand['1'].'">'.$listabrand['0'].' - '.$listabrand['1'].'</option>';
}?>
</select>
<label>BRAND'S NAME TO MODIFY</label>
<input type="text" name='brand-name'>
<button type="submit" name='modify-btn' class="btn btn-default">Modifica</button>
</form>
.....
<script>
$('select[name="brands-list"]').change(function(){
var selectedBrand = $(this).val();
$('input[name="brand-name"]').val(selectedBrand);
});
</script>
update_brand.php
<?php
require '../sys/conn.php';
$mod_brand=$_POST['brand-name']
if (isset($_POST['modify-btn'])){
$brand=mysqli_real_escape_string($conn, $mod_brand] );
if ($mod_brand !=''){
$update = mysqli_query($conn,"
UPDATE mg_terms SET name= $brand
WHERE term_id=......... // THIS IS WHERE THE ID OF SELECTED BRAND SHOULD BE PLACED
");
header('Location: ../pages/success.html');}
else{header('Location: ../pages/error.html');}}
mysqli_close($conn);
?>
Hope I was enoughly clear.