If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > PHP > PHP autofill textfield from mysql dropdown menu

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-02-09, 07:15
ud2008 ud2008 is offline
Registered User
 
Join Date: Apr 2009
Posts: 1
Question PHP autofill textfield from mysql dropdown menu

have a selection menu created with php which is linked to a mysql database.
Now when I select an item in that menu, I want that from an other column in the same database the email is displayed in a text field. (for example: I select dave in the selection menu, I want his email address to be displayed in the text field.)

The code doesn't seem to work, all I get is a text field with array as text in it and not the email.

Here is the code, please help.
Code:
<?php
	require(HESK_PATH . 'inc/database.inc.php');
	hesk_dbConnect();
	$sql = 'SELECT naam FROM `'.$hesk_settings['db_pfix'].'names`';
	$result = hesk_dbQuery($sql);
	while ($row=hesk_dbFetchAssoc($result))
	{
	    if ($_SESSION['c_name'] == $row['id']) {$selected = ' selected="selected"';}
	    else {$selected = '';}
	    echo '<option value="'.$row['id'].'"'.$selected.'>'.$row['naam'].'</option>';
	}
	{
		if( isset ($_POST['naam'])) {
		}
	$query = 'SELECT email FROM `'.$hesk_settings['db_pfix'].'names` WHERE email = '' . mysql_real_escape_string( $_POST['naam'] ) . ''';
	$result = mysql_query( $query ); 
        if( $result !== false ) 
        { 
            if( mysql_num_rows( $result ) == 1 ) 
            { 
			}
		}
    ?>
and here the text field code:
Code:
<input type="text" name="email" size="40" maxlength="50" value="<?php echo stripslashes(hesk_input($_SESSION['c_email']));?>" />
Reply With Quote
  #2 (permalink)  
Old 04-02-09, 13:24
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
have you verified the SQL is correct by running it in soemhtign like MySQL Query Browser or another sutiable tool.

have you then checked that the SQL you are sending to the SQL engine is waht you think it is

my reading of your SQL makes me think there is a problem there
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On