TheStalker Posted July 18, 2008 Share Posted July 18, 2008 Hi, i have this form that auto fills text boxes but i cant work out how to make the drop down lists do the same? The customer details are in a table called customers. Can some on point me towards how this is done please ? any help would be great this is the code that seems to work for the text boxes atm <center> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="POST" name="names"> <table border='0' > <tr> <td><p>Select A CustomerID:</p></td> <td> <SELECT NAME='results' onchange="this.form.submit();"> <?php $query = "SELECT CustomerID FROM customers"; $result = mysql_query($query); while ($line = mysql_fetch_array($result)) { echo "<OPTION value='$line[0]'>$line[0]</OPTION>"; }?> </SELECT> </td> </tr> <?php if($value=$_POST['results']){ $result = mysql_query("SELECT * FROM customers WHERE CustomerID = '$value'"); $customerID = mysql_result($result,0,'customerID'); $surname = mysql_result($result,0,'surname'); $forename = mysql_result($result,0,'forename'); $addressLine1 = mysql_result($result,0,'addressLine1'); $addressLine2 = mysql_result($result,0,'addressLine2'); $postcode = mysql_result($result,0,'postcode'); } ?> </form> <form action="insertEditCustomer.php" onsubmit ="return validate_form(this)" method="post"> <tr> <td><br></td> <td><br></td> </tr> <tr> <td>Customer ID: </td> <td><input type="text" readonly="readonly" size ="1" name="customerID" value="<?php echo $customerID ?>" /></td> </tr> <tr> <td><p>Surname:</td> <td><input type="text" name="surname" value="<?php echo $surname ?>" /></td> </tr> <tr> <td><p>Forename:</td> <td><input type="text" name="forename" value="<?php echo $forename?>"/></td> </tr> <tr> <td><p>Adress Line 1:</td> <td><input type="text" name="addressLine1" value="<?php echo $addressLine1?>"/></td> </tr> <tr> <td><p>Adress Line 2:</td> <td><input type="text" name="addressLine2" value="<?php echo $addressLine2?>"/></td> </tr> <tr> <td><p>Postcode:</td> <td><input type="text" name="postcode" value="<?php echo $postcode?>"/></td> </tr> <!--------------------------------Daily newspapers---------------------------> <td><p>Daily Newspapers: </p></td> <td> <SELECT NAME='daily1' width='300' style='width: 145px' > <?php $query = "SELECT paper FROM dailyPapers"; $result = mysql_query($query); while ($line = mysql_fetch_array($result)) { echo "<OPTION value='$line[0]'>$line[0]</OPTION>"; }?> </SELECT> </td> <td> <SELECT NAME='daily2' width='300' style='width: 145px' > <?php $query = "SELECT paper FROM dailyPapers"; $result = mysql_query($query); while ($line = mysql_fetch_array($result)) { echo "<OPTION value='$line[0]'>$line[0]</OPTION>"; }?> </SELECT> </td> <td> <SELECT NAME='daily3' width='300' style='width: 145px' > <?php $query = "SELECT paper FROM dailyPapers"; $result = mysql_query($query); while ($line = mysql_fetch_array($result)) { echo "<OPTION value='$line[0]'>$line[0]</OPTION>"; }?> </SELECT> </td> </tr> Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted July 18, 2008 Share Posted July 18, 2008 is there a row in the table called 0? Quote Link to comment Share on other sites More sharing options...
TheStalker Posted July 18, 2008 Author Share Posted July 18, 2008 in the table there is : customerID surname forename addressLine1 addressLine2 postcode dailyNewspaper1 dailyNewspaper2 dailyNewspaper3 Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted July 18, 2008 Share Posted July 18, 2008 then this won't work echo "<OPTION value='$line[0]'>$line[0]</OPTION>"; it should be $line['']; and one of these customerID surname forename addressLine1 addressLine2 postcode dailyNewspaper1 dailyNewspaper2 dailyNewspaper3 Quote Link to comment Share on other sites More sharing options...
TheStalker Posted July 18, 2008 Author Share Posted July 18, 2008 sorry i missed some of the code that goes before out ive added it in in the right place Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted July 18, 2008 Share Posted July 18, 2008 solved? Quote Link to comment Share on other sites More sharing options...
TheStalker Posted July 18, 2008 Author Share Posted July 18, 2008 no the code that i have just dose the text boxes ive been playing around with it but no such luck. The drop down list are populated by data from another table dailypapers. but i want to auto fill the drop down list with the newspaper that the customer has in their records so it could then be changed if needed. If that makes sense This is the full code that auto fills the texts boxes: <form action="<?php echo $_SERVER['PHP_SELF']?>" method="POST" name="names"> <table border='0' > <tr> <td><p>Select A CustomerID:</p></td> <td> <SELECT NAME='results' onchange="this.form.submit();"> <?php $query = "SELECT CustomerID FROM customers"; $result = mysql_query($query); while ($line = mysql_fetch_array($result)) { echo "<OPTION value='$line[0]'>$line[0]</OPTION>"; }?> </SELECT> </td> </tr> <?php if($value=$_POST['results']){ $result = mysql_query("SELECT * FROM customers WHERE CustomerID = '$value'"); $customerID = mysql_result($result,0,'customerID'); $surname = mysql_result($result,0,'surname'); $forename = mysql_result($result,0,'forename'); $addressLine1 = mysql_result($result,0,'addressLine1'); $addressLine2 = mysql_result($result,0,'addressLine2'); $postcode = mysql_result($result,0,'postcode'); } ?> </form> <form action="insertEditCustomer.php" onsubmit ="return validate_form(this)" method="post"> <tr> <td><br></td> <td><br></td> </tr> <tr> <td>Customer ID: </td> <td><input type="text" readonly="readonly" size ="1" name="customerID" value="<?php echo $customerID ?>" /></td> </tr> <tr> <td><p>Surname:</td> <td><input type="text" name="surname" value="<?php echo $surname ?>" /></td> </tr> <tr> <td><p>Forename:</td> <td><input type="text" name="forename" value="<?php echo $forename?>"/></td> </tr> <tr> <td><p>Adress Line 1:</td> <td><input type="text" name="addressLine1" value="<?php echo $addressLine1?>"/></td> </tr> <tr> <td><p>Adress Line 2:</td> <td><input type="text" name="addressLine2" value="<?php echo $addressLine2?>"/></td> </tr> <tr> <td><p>Postcode:</td> <td><input type="text" name="postcode" value="<?php echo $postcode?>"/></td> </tr> <!--------------------------------Daily newspapers---------------------------> <td><p>Daily Newspapers: </p></td> <td> <SELECT NAME='daily1' width='300' style='width: 145px' > <?php $query = "SELECT paper FROM dailyPapers"; $result = mysql_query($query); while ($line = mysql_fetch_array($result)) { echo "<OPTION value='$line[0]'>$line[0]</OPTION>"; }?> </SELECT> </td> <td> <SELECT NAME='daily2' width='300' style='width: 145px' > <?php $query = "SELECT paper FROM dailyPapers"; $result = mysql_query($query); while ($line = mysql_fetch_array($result)) { echo "<OPTION value='$line[0]'>$line[0]</OPTION>"; }?> </SELECT> </td> <td> <SELECT NAME='daily3' width='300' style='width: 145px' > <?php $query = "SELECT paper FROM dailyPapers"; $result = mysql_query($query); while ($line = mysql_fetch_array($result)) { echo "<OPTION value='$line[0]'>$line[0]</OPTION>"; }?> </SELECT> </td> </tr> Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted July 18, 2008 Share Posted July 18, 2008 as i said $list['0'] is wong, you should enter a table row like $list['row'] Quote Link to comment Share on other sites More sharing options...
TheStalker Posted July 18, 2008 Author Share Posted July 18, 2008 so you mean this "<OPTION value='$line['row']'>$line['row']</OPTION>"; Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted July 18, 2008 Share Posted July 18, 2008 yes with the row name in it Quote Link to comment Share on other sites More sharing options...
TheStalker Posted July 18, 2008 Author Share Posted July 18, 2008 liek this? "<OPTION value='$line['dailyNewspaper1']'>$line['dailyNewspaper1']</OPTION>"; i get this Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\wamp1\www\R&V Project\editCustomer.php on line 172 Quote Link to comment Share on other sites More sharing options...
TheStalker Posted July 18, 2008 Author Share Posted July 18, 2008 should i not be using a variable like $daily1 ? $daily1 = mysql_result($result,0,'dailyNewspaper1'); echo "<OPTION value='$line[$daily1]'>$line[$daily1]</OPTION>"; some thing like this??? Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted July 18, 2008 Share Posted July 18, 2008 not this "<OPTION value='$line['dailyNewspaper1']'>$line['dailyNewspaper1']</OPTION>"; this <OPTION value="$line['dailyNewspaper1']">$line['dailyNewspaper1']</OPTION> Quote Link to comment Share on other sites More sharing options...
TheStalker Posted July 19, 2008 Author Share Posted July 19, 2008 not this "<OPTION value='$line['dailyNewspaper1']'>$line['dailyNewspaper1']</OPTION>"; this <OPTION value="$line['dailyNewspaper1']">$line['dailyNewspaper1']</OPTION> i tried that and got this Parse error: syntax error, unexpected '<' in C:\wamp1\www\R&V Project\editCustomer.php on line 172 Do i need the echo and the ""; ? Quote Link to comment Share on other sites More sharing options...
TheStalker Posted July 19, 2008 Author Share Posted July 19, 2008 just tried this echo "<OPTION value="$line['dailyNewspaper1']">$line['dailyNewspaper1']</OPTION>"; and got this Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in C:\wamp1\www\R&V Project\editCustomer.php on line 172 Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted July 19, 2008 Share Posted July 19, 2008 echo "<OPTION value='$line['dailyNewspaper1']'>$line['dailyNewspaper1']</OPTION>"; that should work Quote Link to comment Share on other sites More sharing options...
TheStalker Posted August 5, 2008 Author Share Posted August 5, 2008 ive just found out how to do this. This is what i needed to include <SELECT NAME='daily1' width='300' style='width: 145px' > <?php $query = "SELECT paper FROM dailyPapers"; $result = mysql_query($query); while ($line = mysql_fetch_array($result)) { echo "<option"; if($line[0]==$daily1) echo " selected"; echo " value='$line[0]'>$line[0]</OPTION>"; }?> </SELECT> 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.