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.

provdata.png

Here's what it looks like.

provider.png

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

}

I see a few things that stand out to me in your provider form-control snippet.

First, in line 6 you are selecting provider twice from mandates. Perhaps that is not that big of a deal, but it seems unnecessarily redundant.
$prov = "SELECT provider,provider FROM mandates GROUP BY provider";

Second, in line 9, you are referencing $row[provider] before the while loop.

Third, in line 12, you are referencing an array by an index name without quotes. This applies to line 9, as well:
$row[provider] should be $row['provider'].

I would suggest the following edit to line 12:
echo '<option value="' . $row['provider'] . '">' . $row['provider'] . '</option>';

Which should be interpreted as:
<option value="Isabel Something">Isabel Something</option>

instead of:
<option value=Isabel Something>Isabel Something</option>

(where the 'Something' inside the option tag would be interpreted as a tag attribute (e.g.; 'selected', 'disabled', etc.), see <option>: The HTML Option element.

commented: Thank you. Before I read your comment I tried something and it worked. =) But thank you for this, I will note everything. +0

I know you mention you already got it working, but I will echo gce's note that the reason the full name isn't being understood is because you are missing quotes around it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.