Reputation: 344
I pulling text that is stored in my database using MySQL select so it is displayed in a form so it can be edited.
When the form is set to the string held in the database gets truncated at the first space so "Foo Bar" would be displayed as "Foo". This doesn't happen when using the tag.
I have made sure that the text field is big enough to hold the entire string and the number of charters isn't limited.
In the database the whole word is stored and no truncation is happening. I set the type to varchar(30) which is enough space to store the whole word. I have also tried changing the type to text and I still have the problem.
I can't seam to find a solution anywhere does anyone have an idea of why this may be happening?
<?php echo "<input type=\"text\" name=\"title[" . $row["id"] . "]\" value=" . $row["title"] . ">"; ?>
Upvotes: 0
Views: 96
Reputation: 129403
You should provide a sample of the HTML produced from your php page. Most likely, your value string is not being quoted, e.g. your HTML form looks like:
<input type=text value=Foo Bar>
instead of
<input type=text value="Foo Bar">
This would produce exactly the effect you are seeing
UPDATE: Based on your example in the comment, you are indeed missing the quotes:
Old code with the problem (missing quotes around value attribute's value):
<?php echo "<input type=\"text\" name=\"title[" . $row["id"] . "]\"
value=" . $row["title"] . ">"; ?>
Fixed code:
<?php echo "<input type=\"text\" name=\"title[" . $row["id"] . "]\"
value=\"" . $row["title"] . "\">"; ?>
Note that you already had the name
attribute correctly quoted, but value
was not.
Upvotes: 2
Reputation: 6748
Without the relevant code, this is just a guess, but are you setting your form input value attributes without using quotes?
For example, are you doing this?
<input type="text" value=<? echo $value; ?> name="formInput" />
Instead of the correct syntax, which is this?
<input type="text" value="<? echo $value; ?>" name="formInput" />
Upvotes: 2