Advanced Search

Results 1 to 4 of 4

Thread: Problem Populating form from mysql database

  1. #1
    Join Date
    Jul 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem Populating form from mysql database

    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.
    Last edited by boxelder_bee; 07-20-2009 at 05:09 PM. Reason: more clarification

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,623
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    it's kinda hard to offer any help without seeing the code you're using.
    We Only Torture the Folks We Don't Like (You're Probably Gonna Be Okay)
    It's a Party in the CIA

  3. #3
    Join Date
    Jul 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Okay, sorry.

    Code:
    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
    Code:
    $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?

  4. #4
    Join Date
    Jul 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default fixed

    Okay so i figured out what i was doing wrong. I just was going about it the wrong way.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •