I have this form where I'm editing a student's information like changing the provider assigned to him. I'm having a problem with it since the dropdown menu is coming from MySQL database that has the full name.
Here's what it looks like.
When I try to select one provider and save it, the provider data only saves the name not including the surname. Here's the code I have in my provider form-control:
<div class="col-sm-3">
<div class="form-floating">
<?php
$prov = "SELECT provider,provider FROM mandates GROUP BY provider";
if($r_set=$con->query($prov)){
echo "<SELECT class='form-control' id='floatingSelectGrid' name=prov>";
echo "<option selected>$row[provider]</option>" ;
while($row=$r_set->fetch_assoc()){
echo "<option value=$row[provider]>$row[provider]</option>";
}
echo "</select>";
}else{
echo $con->error;
}
?>
<label for="floatingSelectGrid">Provider</label>
</div>
</div>
And here's the code when I save it:
if(isset($_POST['save_student']))
{
$student_id = mysqli_real_escape_string($con,$_POST['student_id']);
$nycid = mysqli_real_escape_string($con,$_POST['nycid']);
$firstname = mysqli_real_escape_string($con,$_POST['firstname']);
$lastname = mysqli_real_escape_string($con,$_POST['lastname']);
$grade = mysqli_real_escape_string($con,$_POST['grade']);
$adbn = mysqli_real_escape_string($con,$_POST['adbn']);
$pldbn = mysqli_real_escape_string($con,$_POST['pldbn']);
$stype = mysqli_real_escape_string($con,$_POST['stype']);
$mb = mysqli_real_escape_string($con,$_POST['mb']);
$language = mysqli_real_escape_string($con,$_POST['language']);
$ig = mysqli_real_escape_string($con,$_POST['ig']);
$gsize = mysqli_real_escape_string($con,$_POST['gsize']);
$freq = mysqli_real_escape_string($con,$_POST['freq']);
$dur = mysqli_real_escape_string($con,$_POST['dur']);
$provider = mysqli_real_escape_string($con,$_POST['prov']);
$query = "UPDATE mandates SET
id='$student_id',
nycid='$nycid',
lastname='$lastname',
firstname='$firstname',
grade='$grade',
adbn='$adbn',
pldbn='$pldbn',
stype='$stype',
mb='$mb',
language='$language',
ig='$ig',
gsize='$gsize',
freq='$freq',
dur='$dur',
provider='$provider'
WHERE id='$student_id'";
$query_run = mysqli_query($con,$query);
if($query_run)
{
$_SESSION['message'] = "Student has been updated successfully!";
header("Location: mandates.php");
exit(0);
}
else
{
$_SESSION['message'] = "Student not updated!";
header("Location: mandates.php");
exit(0);
}
}