Prefilling Forms (Quotes problem?)

Hi… I’m trying to make a form to edit a database entry that will be pre-populated with the current contents of the row being modified. Unfortunately, I only seem to be able to get it to pre-populate with the first word in each field (as in, if I had “two words” in a field, what would show up in my form is the word “two”).

I’ve spent quite a while poking around on the web, and I’m 75% certain that my problem has something to do with my use/positioning of quotes, since that frequently seems to cause just this issue in just this situation, but none of the solutions I’ve found seem to help… Any advice would be much appreciated, I’m thoroughly stuck.

Code is currently as follows:


<?php require("dbinfo.php"); $con = mysql_connect("localhost", $username, $password); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db($database, $con); $result = mysql_query("SELECT * FROM main WHERE id='$_POST[id]'"); while($row = mysql_fetch_array($result)) { echo ""; echo "
"; echo "Name:
"; echo "Type: Food Pantry Soup Kitchen Shelter Other
"; echo "Address:
"; echo "State:
"; echo "Phone:
"; echo "E-mail:
"; echo "Website:
"; echo "Hours:
"; echo "Requirements:
"; echo "Additional Information:
"; echo ""; echo ""; } mysql_close($con); ?>


You need to surround values with quotes, either single or double. In your case if you use double quotes in html form fields, you need to escape them with
Example of correct code with single quotes:
[php]echo “Address: <input type=‘text’ name=‘address’ value=’”.$row[‘address’]."’>
Example of correct code with double quotes:
[php]echo “Address: <input type=‘text’ name=‘address’ value=”".$row[‘address’]."">

Sponsor our Newsletter | Privacy Policy | Terms of Service