0

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"] . ">"; ?>
2
  • It is hard to tell where that error might be come from because you have not posted any code. Normally this does not happen is all I can say. Commented Aug 30, 2012 at 16:09
  • 2
    Please provide us with a SSCCE. Without any code it is hard to help you. Commented Aug 30, 2012 at 16:10

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I just had a look and it was not being quoted. It can be hard to tell when echoing out using php.
2

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" />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.