Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP/MySql data truncation in HTML textbox 2

Status
Not open for further replies.

jsolutions

Programmer
Jul 18, 2002
157
US
Hi - I am using a form to allow user's to update information. It is an HTML form that contains First Name, Last Name, Address, City, State and Zip. I am using PHP to query a MySQL database to pull the exiting values into the form. Then, the user can edit the information.

So, for example to display the first name in the form, I am using the statement:
Code:
<input type="text" name="firstName" value =  <?php echo "$first"; ?>>
Note:$first was assigned earlier in the code.

This works fine until I hit something that has a space in it, for example, address1. If someone lives at 1459 Woodland Drive, the only thing that shows up is 1459. If I remove the PHP and type in "1459 Woodland Drive" in the value field, it shows up in the textbox.

Any help on this would be greatly appreciated.
 
Your problem is probably an error with your HTML and not your PHP. You haven't enclosed the value of the text input. Try this:

Code:
<input type="text" name="firstName" value ='<?php echo "$first"; ?>'>
 
Thanks Dweezel. Your code pushed me in the right direction. I looked at the page source after the PHP had processed and the tag ended up reading
Code:
<input type="text" name="address1" size = 50 value = 1459 Woodland Drive>

The implication is that "Woodland" and "Drive" are considered parameters of the input tag since they are not properly quoted. Since these parameters don't exist, they are ignored.

The key was proper quoting. The example you gave did not seem to give me the result I wanted but pushed me in the right direction. I came up with the following:

Code:
<input type="text" name="address1" size = 50 value =   <?php echo '"' . "$address1" . '"'; ?>>

This worked! I am guessing there is probably a better (and more eloquent) way to write this. I am still very new to PHP. If you have a cleaner way to write it, please let me know.

Thanks again Dweezel!
 
try
Code:
<input type="text" name="address1" size = 50 value = "<?=$address1?>">
the short form tag <?= ... ?> means evaluate the variable/function etc and print it. the single quotes suggested by Dweezel should work unless, I believe, you use strict xhtml in which case double quotes are needed (could be wrong on this, I use quirks mode)
 
jpadie said:
should work unless, I believe, you use strict xhtml in which case double quotes are needed (could be wrong on this, I use quirks mode)
You would be wrong. XHTML requires quoted attributes, it never says which quotes though.
 
jpadie - Thanks so much for the code. MUCH CLEANER than my approach. Easier to read and understand. Really appreciate it as I have 12 fields that I am outputting. Will Make maintaining it so much easier.

Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top