Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Location
    Velsen Noord, Netherlands
    Posts
    219
    Thanks
    6
    Thanked 0 Times in 0 Posts

    PHP autofill textfield from mysql dropdown menu

    I 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:
    <td width="80%"><input type="text" name="email" size="40" maxlength="50" value="<?php echo stripslashes(hesk_input($_SESSION['c_email']));?>" /></td>

  2. #2
    Master Coder Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,692
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Where is your $_SESSION['c_email'] getting assigned a value? It doesn't appear you are fetching anything from your SELECT email FROM query.


 

Posting Permissions

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