简体   繁体   中英

Dropdown box in php getting partial values from mysqli database

When I am trying to list all the employee names from the database to assign a job for a particular person in the dropdown box. The Output value only show the initial or the First name of Employee. The other names of the employee (Last names) are not posted in the php.

Actually the names after first spaces are missing.

Here is my code...

<pre>
<tr>
<td><label>Assigning To</label></td><td><label>:</label></td>
<td>
<?php
 $result = mysqli_query($conn, "SELECT * FROM userdetails WHERE UserGroup='DigitizationArtist' || UserGroup='DigitizationArtistQC' || UserGroup='GraphicArtist' || UserGroup='GraphicArtistQC')");
 echo "<select name='ArtistName' value=''>";
 echo "<option value=''></option>";
 while($r = mysqli_fetch_array($result))
 {
 echo "<option value=" .$r['Name'] .">".$r['Name']. "</option>"; 
 }
 echo "</select>";
?>
</td>
</tr>
<pre>

This is the getting value php code...

 $ArtistName = mysqli_real_escape_string($conn, $_POST['ArtistName']);

I am getting the out for "S Gowri Shankar" is "S" I am getting the out for "Selva Kumar" is "Selva"

Please advise. What is wrong in these coding? Else the php always ignore the space after text in checkbox values.

You value attributes has missing closing quotes:

echo "<option value=" .$r['Name'] .">".$r['Name']. "</option>";

Should be:

echo "<option value='" .$r['Name'] ."'>".$r['Name']. "</option>";
                    ^                ^

And also use htmlspecialchars for those values with quotations so that they wont mess up the closing on the attributes:

$ArtistName = mysqli_real_escape_string($conn, $_POST['ArtistName']);
$ArtistName = htmlspecialchars($ArtistName, ENT_QUOTES);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM