简体   繁体   English

PHP中的下拉框从mysqli数据库获取部分值

[英]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. 输出值仅显示Employee的名字或名字。 The other names of the employee (Last names) are not posted in the php. 员工的其他姓名(姓氏)未发布在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... 这是获取价值的php代码...

 $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" 我要出演“ S Gowri Shankar”是“ S”我要出演“ Selva Kumar”是“ Selva”

Please advise. 请指教。 What is wrong in these coding? 这些编码有什么问题? Else the php always ignore the space after text in checkbox values. 否则,PHP始终会忽略复选框值中的文本后的空格。

You value attributes has missing closing quotes: 您的value属性缺少右引号:

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: 还要对这些带有引号的值使用htmlspecialchars ,以使它们不会弄乱属性的结尾:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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