elm Posted October 5, 2010 Share Posted October 5, 2010 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 "<form action='update.php' method='post'>"; echo "<input type='hidden' name='id' value=".$_POST['id']."><br>"; echo "Name: <input type='text' name='name' value=".$row['name']."><br>"; echo "Type: <select name='type' value=".$row['type']."> <option value='Food Pantry'>Food Pantry</option> <option value='Food Pantry'>Soup Kitchen</option> <option value='Food Pantry'>Shelter</option> <option value='Food Pantry'>Other</option></select><br>"; echo "Address: <input type='text' name='address' value=".$row['address']."><br>"; echo "State: <input type='text' name='state' value=".$row['state']."><br>"; echo "Phone: <input type='text' name='phone' value=".$row['phone']."><br>"; echo "E-mail: <input type='text' name='email' value=".$row['email']."><br>"; echo "Website: <input type='text' name='website' value=".$row['website']."><br>"; echo "Hours: <input type='text' name='hours' value=".$row['hours']."><br>"; echo "Requirements: <input type='text' name='requirements' value=".$row['requirements']."><br>"; echo "Additional Information: <input type='text' name='additional' value=".$row['additional']."><br>"; echo "<input type='submit' />"; echo "</form>"; } mysql_close($con); ?> Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 5, 2010 Share Posted October 5, 2010 i would single-quote and htmlspecialchars your values, for example echo "Name: <input type='text' name='name' value='".htmlspecialchars($row['name'], ENT_QUOTES))."'><br>"; Quote Link to comment Share on other sites More sharing options...
elm Posted October 5, 2010 Author Share Posted October 5, 2010 You've got an extra ) in there, but after removing it, your example works like a charm. Thank you! i would single-quote and htmlspecialchars your values, for example echo "Name: <input type='text' name='name' value='".htmlspecialchars($row['name'], ENT_QUOTES))."'><br>"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.