473,486 Members | 2,424 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

forms value and php echo stops after first space

The title is maby a bit strage, I had problem coming up with a title
that explain my problem.

I have a variable $myvar="TEST 123"

I would like to use this variable as a default value in a form. I have
tryed this code:

<input name="testbox1" type="text" value=<?php echo "$myvar"; ?>>
the result is a form with a textbox with the default value "TEST"

I have tryed

<input name="testbox2t" type="text" value=<?php echo "TEST 123"; ?>>
Same as before the default value is only "TEST"

But if I try

<input name="testbox 3t" type="text" value= "TEST 123t">
the default value is "TEST 123"

all my test code is inside the <form> </form> statement
Mar 25 '06 #1
4 9456
All text values must be inside " "
If the parser comes and sees this:

value=TEST 123

he will take TEST but he will think 123 is another attribute of the
tag.

The best way would be this:

<input name="textbox2" type="text" value="<?php echo $myvar ?>" />

Mar 25 '06 #2
Somebody:

[$myvar='TEST 123';]
<input name="testbox1" type="text" value=<?php echo "$myvar"; ?>>
the result is a form with a textbox with the default value "TEST"


You are obviously aware that the value must be within quotes in the
HTML, but if you look at the HTML source you'll see the value is not
quoted, which causes the value to be cut off after 'TEST'. PHP
interprets what's after echo here as a string delimited by double quote
marks, that string being the variable $myvar, and only the value of
that string, not the quote marks as well, is echo-ed.

Two options. Either include the quotes in the echo-ed string (there
are various ways) or include them directly in the markup. Given the
advice to always quote attribute values, the latter seems more
appropriate.

--
Jock

Mar 25 '06 #3
Thanks to both of you. The solution was so obvious that I feel almost
like an idiot not seeing it myself.
Mar 25 '06 #4
If you had viewed the source from the browser you may have spotted what
it was doing, I find the old "View Source" option great for debugging
variable display code and other similar areas in my scripts.

Mar 26 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1141
by: Col | last post by:
Hi all, I'm new at asp and there may be an obvious answer but I haven't found it yet. I have 3 pages on page 1 there is a select box, name="UD", containing "Data B" page1 submits to page...
3
29720
by: 2Dcube | last post by:
Hello, I'm doing some PHP and MySQL, and have a very simple question. How do you echo a long space? When I use echo " ": , it gets echo'd as only one space... Using echo " "; echo " ";...
1
1134
by: staumchase | last post by:
I'm trying to get an MS Access query (in Access 2002) to fill in the values of a previous record as long as the current record is null For example, if I have the following table: XNUMBER NAME...
2
1758
by: nospam | last post by:
-------------------------------------------------------------------------------- I have a subform with the related IDs for each customer on the customer main form. I have a button on the...
17
2733
vikas251074
by: vikas251074 | last post by:
I have create form as below - <table> <tr> <td align="right">VLAN Name : </td> <td> <select name="vlan_name" style="width:150px "> <% ...
2
1087
by: LLM | last post by:
I have a tab control on a windows form. I moved a bunch of stuff from one tab to another and then rearranged it but for the life of me, I can't get the tab stops to set. In the past I go to view ->...
5
3469
by: Johny | last post by:
How can I find the first space using regex? For example I have text Text=' This is a sample ' The last space I can remove by Text=re.sub(r"\s(?!\w)",'',Text) but I do not know how to...
14
5853
by: cobolguy | last post by:
I am trying to add the cr/lf characters to a form text box. I have used both text and a memo field that is set for Rich Text. I can add them to a string, display the string in a message box - but...
51
6831
by: sarega | last post by:
Hi, I have to extract the value entered in the first text box and based on the value entered have to populate the second text box. Eg:if the value entered in first text box is like home/version...
0
7100
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6964
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6842
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5434
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4865
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
262
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.