Jump to content


Photo

Drop down list selection into text fields


  • Please log in to reply
5 replies to this topic

#1 avo

avo
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts
  • Locationstaffordshire uk

Posted 27 April 2006 - 08:57 PM

Hi All

Im a little stuck on this one can anyone please help me out

what i have done is populated a list box with the username row of my sql table .
but now im trying to populate the text field of a form starting with the username then i will populate the other files in my html table .

if i click edit user button with select user in the drop down list the username then gets filled with select username but when i select one of the users from the dropdown all i get is array in the text field.
my code is :

<?php
//session_start ();

// include db file
include ("includes/dbconfig.php");


mysql_connect ($dbhost, $dbuser, $dbpass);
mysql_select_db ($dbname) or die ( mysql_error ());
$query = "SELECT username FROM members ORDER BY username ASC"; 
$result = mysql_query ($query) or die ( mysql_error () );

if ($_POST ['Edit_user']) {
$frm_username = ($_POST ['List_box']); 
}
?>

<style type="text/css">
<!--
.style1 {color: #FF0000}
-->
</style>


<form id="form1" name="form1" method="post" action="">
  <table width="262" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td width="119"><div align="center">
      
      <select name="List_box">
        <option>Select User</option>
        
        <?
        while($nt=mysql_fetch_array($result)) { //gets information from database loops till all username are gathered
        echo "<option value=$nt >$nt[username]</option>"; } //dispalys username(s) in value tag 
        ?>
        
      </select>
      
      </div></td>
      <td width="125">
        <div align="center">
          <input name="Edit_user" type="submit" class="style1" value="Edit User" />
        </div></td>
    </tr>
    <tr>
      <td> </td>
      <td> </td>
    </tr>
  </table>
  <table border="0" align="center" cellpadding="0" cellspacing="2">
    <tr>
      <td colspan="2" align="center">
    </tr>
    <tr>
    </tr>
    <tr>
      <td>Username</td>
      <td><input name="muser" type="text" value="<? echo $frm_username; ?>" /></td>
    </tr>
    <tr>
      <td>Password</td>
      <td><input type="text" name="puser" /></td>
    </tr>
    <tr>
    <td>Confirm Password</td>
    <td><input type="text" name="cpuser" /></td>
    </tr>
    <tr>
      <td colspan="2"> </td>
    </tr>
    <tr>
      <td>Name</td>
      <td><input name="mname" type="text" value="" /></td>
    </tr>
    <tr>
      <td>E-mail Address </td>
      <td><input name="memail" type="text" value="" /></td>
    </tr>
    <tr>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td><input name="udinfo" type="submit" class="style1" value="Up-Date Info" /></td>
      <td> </td>
    </tr>
  </table>
</form>
<p> </p>

all help appriciated just need pointing in the right direction

thanks.
Im loving it ........

#2 spInGoBlin

spInGoBlin
  • Members
  • Pip
  • Newbie
  • 4 posts

Posted 27 April 2006 - 09:24 PM

Hi,
Have you tried refreshing the page after selection, and using hidden fields to store the selection? :
1. <form id="form1" name="form1" method="post" action="form1.php?go=yes">
2. in option list: <select name="List_box" onclick="Refresh(0)">
3. Add a hidden text box:
<input type="hidden" name="ListSelection">
4. Add Javascript function:
function Refresh()
{
form01["ListSelection"].value = form01["List_Box"].value;
document.form01.submit();
}
5. After that refer to selected field as $ListSelection in PHP

Hope that helps.

#3 avo

avo
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts
  • Locationstaffordshire uk

Posted 28 April 2006 - 06:32 AM

Hi all


Any help on this one please.

Thanks.
Im loving it ........

#4 sanfly

sanfly
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationNew Zealand

Posted 28 April 2006 - 11:52 AM

Give the code below a whirl. There may be a syntax error or two, cant test it myself

Basically what i have done, is when you press edit user, it reloads the page and inserts the appropriate data into the fields.

Also have "added" another form element, change "processing_page.php" to whatever page you want to use to update the data.

Hope this helps

<?php
//session_start ();

// include db file
include ("includes/dbconfig.php");


mysql_connect ($dbhost, $dbuser, $dbpass);
mysql_select_db ($dbname) or die ( mysql_error ());
$query = "SELECT username FROM members ORDER BY username ASC";
$result = mysql_query ($query) or die ( mysql_error () );

if ($_POST['Edit_user']) {
    $frm_username = ($_POST['List_box']);
    $q2 = "SELECT * FROM members WHERE username = $frm_username";
    $r2 = mysql_query($q2) or die(mysql_error());
        $row2 = mysql_fetch_array($r2);
            $mname = $row2['mname'];
            $memail = $row2['memail'];
}
?>

<style type="text/css">
<!--
.style1 {color: #FF0000}
-->
</style>


<form id="form1" name="form1" method="post" action="<?=$_SERVER['PHP_SELF']?>">
  <table width="262" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td width="119"><div align="center">
      
      <select name="List_box">
        <option>Select User</option>
        
        <?
        while($nt=mysql_fetch_array($result)) { //gets information from database loops till all username are gathered
        echo "<option value=$nt >$nt[username]</option>"; } //dispalys username(s) in value tag
        ?>
        
      </select>
      
      </div></td>
      <td width="125">
        <div align="center">
          <input name="Edit_user" type="submit" class="style1" value="Edit User" />
        </div></td>
    </tr>
    <tr>
      <td> </td>
      <td> </td>
    </tr>
  </table>
 </form> 
  
 <form method="post" action="page_to_process.php">
  <table border="0" align="center" cellpadding="0" cellspacing="2">
    <tr>
      <td colspan="2" align="center">
    </tr>
    <tr>
    </tr>
    <tr>
      <td>Username</td>
      <td><input name="muser" type="text" value="<?=$frm_username; ?>" /></td>
    </tr>
    <tr>
      <td>Password</td>
      <td><input type="text" name="puser" /></td>
    </tr>
    <tr>
    <td>Confirm Password</td>
    <td><input type="text" name="cpuser" /></td>
    </tr>
    <tr>
      <td colspan="2"> </td>
    </tr>
    <tr>
      <td>Name</td>
      <td><input name="mname" type="text" value="<?=$mname?>" /></td>
    </tr>
    <tr>
      <td>E-mail Address </td>
      <td><input name="memail" type="text" value="<?=$memail?>" /></td>
    </tr>
    <tr>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td><input name="udinfo" type="submit" class="style1" value="Up-Date Info" /></td>
      <td> </td>
    </tr>
  </table>
</form>
<p> </p>

If you're not part of the solution, you're part of the precipitate

#5 avo

avo
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts
  • Locationstaffordshire uk

Posted 28 April 2006 - 01:31 PM

HI

First thank you for your reply it makes a lot more sense the way it is now layed out but when i now press the edit user button i get a error ,error is

Unknown column 'Array' in 'where clause'


new error on me

Any suggestions please

Thanks again.
Im loving it ........

#6 sanfly

sanfly
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationNew Zealand

Posted 28 April 2006 - 07:37 PM

Okay, its because of this

<?
        while($nt=mysql_fetch_array($result)) { //gets information from database loops till all username are gathered
        echo "<option value=$nt >$nt[username]</option>"; } //dispalys username(s) in value tag
        ?>


you have the value of the option tag as being an array. Sorry i missed it earlier

Change to this

<?    while( $nt = mysql_fetch_array($result)) { ?>
            <option value="<?=$nt[username]?>"><?=$nt[username]?></option>
<?    } ?>

If you're not part of the solution, you're part of the precipitate




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users