Home > OS >  Values given to $_POST only contain the first word instead of whole string
Values given to $_POST only contain the first word instead of whole string

Time:02-17

Hi this is example code of problems that i have encountered when trying to send values to the same php file. Var_dump($_GET) Only show the first word instead of the whole value that is submitted to $_GET(eg. when submitting value "Peter Parker", the value shown on var_dump($_GET) is "Peter". But i need to get the whole string for my code to work but i am not sure what is wrong here. I have tried changing it to post but it does not help.

I wrote this in php file.

<html>
    <?php
       $names=array("Peter Parker","Bruce Wayne","Clark Kent");
    
echo "<form action='test.php'>
<select name='superheroes'>
";
foreach($names as $name){
    echo "<option value=$name>$name</option>";
}
echo "</select>
<input type='submit'>
</form>";


var_dump($_GET);
print_r($_GET);
?>

</html>

CodePudding user response:

You need to put your value in quotes.

echo "<option value=\"$name\">$name</option>";

CodePudding user response:

value must be enclosed within quotes.
  • Related