Only the first word is displayed. The variable of several words is displayed

In my form, I have the following values ​​that are based on a standard PHP / MySql query.

echo "<tr>\n <td align='right'><b>Location</b></td> <td><input name='student_location' type='text' size='25' style='font-weight: 700' value=$location></td> </tr>"; 

When the value of $location is one word, it displays correctly when more than one word says only North Campus is displayed.

I doubled and tripled the triple, and the correct value is in the database when I echo the value for $ location, which matches the correct value, but when it appears in the box above it, it breaks the last word. He does this to all my variables, which are more than one word, so I missed something obvious.

+4
source share
3 answers

You forgot quotes:

 echo "<tr>\n <td align='right'><b>Location</b></td> <td><input name='student_location' type='text' size='25' style='font-weight: 700' value=\"$location\"></td> </tr>"; 

Without quotes, the first word will be marked, others will be interpreted as incorrect attributes.

+8
source

You need to put your single quotes around it to make it valid. HTML is created as value=North Campus , which is interpreted as value="North" and some Campus attribute that does not matter. Use value='$location' .

+5
source

you need to quote it by ripping out "

 echo "<tr>\n <td align='right'><b>Location</b></td> <td><input name='student_location' type='text' size='25' style='font-weight: 700' value=\"$location\"></td> </tr>"; 
+4
source

Source: https://habr.com/ru/post/1414963/


All Articles