Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2009

    Question Unanswered: 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.
    	require(HESK_PATH . 'inc/');
    	$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:
    <input type="text" name="email" size="40" maxlength="50" value="<?php echo stripslashes(hesk_input($_SESSION['c_email']));?>" />

  2. #2
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    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 on the Tiger 800 or the Norton

Posting Permissions

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