Jump to content

Prefilling Forms (Quotes problem?)


elm

Recommended Posts

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);
?>

 

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.