I have a form where I display a select item and two other invisible inputs with some variable values that I need to pass to the same page at the press of the “Action” button. But I’m having the problem that those variables are city names like “New York”, so there is a space inside the name, and at the moment of passing the variable only the “New” gets passed; nothing after the space goes with it. I have read that there shouldn’t be any spaces in those variables, so how should I do this?Here is my sample code:// at the beginning of the code I get this variables pass from other pages$pais=$_GET[‘pais’]; $name=$_GET[‘nombre’];// this is how I query my table to populate my select item$SN=mysql_real_escape_string($name);$SP=mysql_real_escape_string($pais);$estadoquery = “SELECT * FROM `”.$SP.”` ORDER BY Estado ASC”;$estadoresult = mysql_query($estadoquery);// this is how I make my form<form method=”post” action=””><input type=”HIDDEN” name=nombre value=””><input type=”HIDDEN” name=pais value=””> Todos <option value=> // and this is what the button action does if(@$_POST[‘ACTION’]==’IR’){$pais = $_POST[‘pais’];$name = $_POST[‘nombre’];$estado = $_POST[‘estado’]; $pais = mysql_escape_string($pais); $name = mysql_escape_string($name); $estado = mysql_escape_string($estado);// this next echos are just to check my variables.echo $pais;echo $name;echo $estado; // so here I can tell that this variable is not complete}And I have read that variables cannot be passed with spaces, why does my $pais variable “United States” gets passed with the space in between correctly? Can someone tell me how to achieve this or how to transform my <option value=> so it can pass the space?php html sql variablesshareimprove this question edited Jul 15 ’13 at 19:27Alex Shesterov9,58072754 asked Oct 27 ’12 at 20:23zvzej2,18152136 The value of a variable can have spaces, the name cannot. For example, $pais can contain “New York”, but the the variable cannot be called $pais name. Make sense? – cale_b Oct 27 ’12 at 20:281 The problem is that you have not put quotes around the option values. Change it like so: <option value=””> and you’ll be good to go. – cale_b Oct 27 ’12 at 20:30 @cale_b this was the solution thank you! – zvzej Oct 27 ’12 at 20:43 You are very welcome. – cale_b Oct 27 ’12 at 20:44add a comment7 Answersactiveoldestvotesup vote2down voteaccepted Per my comment above:The problem is that there are not quotes around the option values. Change it like so:<option value=””> and you’ll be good to go.
Source: How to pass a variable in form using GET with spaces in PHP+HTML+SQL – Stack Overflow