Log in

View Full Version : Problem Populating form from mysql database



boxelder_bee
07-20-2009, 05:07 PM
Okay, So I read the posting "How to populate php/html form with MySQL data"
And I had already gotten the form to retrieve some data from the database but it only retrieves up to the first space. How do I get it to display the complete database entry.

For example:

If company name is "The Honey Jar" it will only display "The" in the form.
If the contact name is "Robbin Williams" It will only display "Robbin".

Any help would be greatly appreciated. I'm just not sure how to get the whole entry back.

I know the problem stems from something associated with the space because when I take out the space between the words it will display the whole entry.

traq
07-20-2009, 07:56 PM
it's kinda hard to offer any help without seeing the code you're using.

boxelder_bee
07-20-2009, 09:51 PM
Okay, sorry.



mysql_connect("----","----","----") or die ("Cannot Connect to Database");
mysql_select_db("----") or die ("could not select database");


$sql1="SELECT * FROM selectedtable WHERE email='----'";
$result1=mysql_query($sql1) or die (mysql_error());

while($row = mysql_fetch_array($result1)){

$checktest=$row['services_array'];
echo $row['public_company_name'];
if ($row['public_company_name']!=null)
{
echo 'Displayed Company Name: <input type="text" name="public_company_name" value=';
echo $row['public_company_name'];
echo ' size="30"><br>';
}
else
echo 'Displayed Company Name:
<input type="text" name="public_company_name" value="" size="30"><br>';



okay so that is the code I am using. It works from what I can tell. But it only returns the first word in the string.
I tried using


$public_company_name=str_replace(" ","&nbsp;",$_POST['public_company_name']);

which uploaded a &nbsp; between the words and worked... or so I thought. But when the user submits the form again without changing the default it replaces the $nbsp; with  and a space behind the symbol.

I tried


$public_company_name=str_replace("Â ","&nbsp;",$row['public_company_name']);


to echo the code on another page after pulling it from the database but it wouldn't replace the  . It just stayed the same. I accomplished the goal of showing the database entry in the form but caused another problem.

Is there a better way to display the value from the database in the form or do I have to just keep fiddling with it until I can get something to work?

boxelder_bee
08-10-2009, 04:21 PM
Okay so i figured out what i was doing wrong. I just was going about it the wrong way.