avo Posted April 27, 2006 Share Posted April 27, 2006 Hi AllIm 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 :[code]<?php//session_start ();// include db fileinclude ("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>[/code]all help appriciated just need pointing in the right direction thanks. Quote Link to comment Share on other sites More sharing options...
spInGoBlin Posted April 27, 2006 Share Posted April 27, 2006 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 PHPHope that helps. Quote Link to comment Share on other sites More sharing options...
avo Posted April 28, 2006 Author Share Posted April 28, 2006 Hi allAny help on this one please. Thanks. Quote Link to comment Share on other sites More sharing options...
sanfly Posted April 28, 2006 Share Posted April 28, 2006 Give the code below a whirl. There may be a syntax error or two, cant test it myselfBasically 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[code]<?php//session_start ();// include db fileinclude ("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>[/code] Quote Link to comment Share on other sites More sharing options...
avo Posted April 28, 2006 Author Share Posted April 28, 2006 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 pleaseThanks again. Quote Link to comment Share on other sites More sharing options...
sanfly Posted April 28, 2006 Share Posted April 28, 2006 Okay, its because of this[code]<? 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 ?>[/code] you have the value of the option tag as being an array. Sorry i missed it earlierChange to this[code]<? while( $nt = mysql_fetch_array($result)) { ?> <option value="<?=$nt[username]?>"><?=$nt[username]?></option><? } ?>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.