如何在PHP中检索全名(两个单词之间的空格)?

如何在PHP中检索全名(两个单词之间的空格)?

问题描述:

Here i am trying to store data into database,It will work successful but when i am seen into database then for Assigned To it will only store first name for example, Value of assign_to=Trilok Dethariya, then in database it will only store Trilok for assign_to field,How can i store full name into it.

<label>Assigned To</label>
<?php 
    $sqll="SELECT Full_name FROM user_master where Role='Project Manager'";
    $rows = $conn->query($sqll);

    echo "<select class='form-control' name='assign_to'>";
    echo "<option value=''>Select One</option>";  

    while($row= $rows->fetch_assoc() ) 
    {
        echo "<option value=".$row['Full_name'].">".$row['Full_name']."</option>";     
    }
    echo "</select>"; 

?>

</div>
</div> 
</form>
<?php
    if ($_SERVER["REQUEST_METHOD"] == "POST")  
    {
        $assign_to = (filter_input(INPUT_POST, 'assign_to'));
    }                       

这里我试图将数据存储到数据库中,它会成功但是当我被看到数据库时那么对于Assigned 它只存储名字,例如,assign_to = Trilok Dethariya的值,然后在数据库中它只存储Trilok for assign_to字段,如何将全名存储到其中。 p>

 &lt; label&gt; Assigned To&lt; / label&gt; 
&lt;?php 
 $ sqll =“SELECT Full_name FROM user_master where Role ='Project Manager'”; 
 $ rows = $ conn-&gt; query($ sqll  ); 
 
 echo“&lt; select class ='form-control'name ='assign_to'&gt;”; 
 echo“&lt; option value =''&gt; Select One&lt; / option&gt;”;  
 
 while($ row = $ rows-&gt; fetch_assoc())
 {
 echo“&lt; option value =”。$ row ['Full_name']。“&gt;”。$ row ['Full_name  “] “&LT; /选项&gt;” 中。  
} 
 echo“&lt; / select&gt;”;  
 
&GT;吗?
 
&LT; / DIV&GT; 
&LT; / DIV&GT;  
&lt; / form&gt; 
&lt;?php 
 if($ _SERVER [“REQUEST_METHOD”] ==“POST”)
 {
 $ assign_to =(filter_input(INPUT_POST,'assign_to')); 
}  
  code>  pre> 
  div>

You must quote attribute values in html:

echo "<option value='".$row['Full_name']."'>".$row['Full_name']."</option>";     

With string interpolation this can be written cleaner as

echo "<option value='{$row['Full_name']}'>{$row['Full_name']}</option>";     

Better yet, normalize your data, and use IDs instead of names:

$sqll="SELECT ID, Full_name FROM user_master where Role='Project Manager'";

...

while($row= $rows->fetch_assoc() ) 
{
    echo "<option value='{$row['ID']}'>{$row['Full_name']}</option>";     
}

Seems like you only post the first row into the Database. Maybe create and extra query / or update your own.

If You wont Full Name Using this logic than You need to some change here

You Have to replace space to underscore between first name and last name, And Where you get value there You have to replace underscore to space. Change Here

 while($row= $rows->fetch_assoc() ) 
    {
        echo "<option value=".str_replace(' ', '_', $row['Full_name']).">".$row['Full_name']."</option>";     
    }