Jump to content

Help with variable being passed to text box


gple

Recommended Posts

I am passing a variable $name into a text box and have the variable text show up in the box so I can later change it and update a record. When the variable is two words like "PHP Freaks", the only thing that appears in the text box is "PHP" it leaves out the second word. Here is the php code that outputs the text box:

echo "Variable: <input name=variable type=text value=". $variable ."><br>";

Any ideas.
The HTML looks like this (when you enter "PHP Freaks"):
[code]<input name=variable type=text value=PHP Freaks>[/code]
The browser doesnt understand to what the word "Freaks" belongs to, so it ignores it.

So what's the solution? Adding double quotes. It's a good habit to do so:
[code]<?php

echo "Variable: <input type=\"text\" name=\"variable\" value=\"".$variable."\">";
//or....
echo 'Variable: <input type="text" name="variable" value="'.$variable.'">';

?>[/code]


Orio.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.