fbm Posted March 3, 2009 Share Posted March 3, 2009 hi, I have a DB with 2 tables [clients] [invoices] My clients table is populated with a bunch of data and the primary key is set to an ID field. Now im trying to create the page where i create an invoice but getting a bit stuck. I want the invoice im creating to know which client ID to be stored against so i added a drop down list option in my form which allows me to select my client and it works great the invoice is added using the below code and the ID is pulled from the drop down selection. My question is how do i get more info out of the drop down list, i want the ID and Company name to be pulled from the client table whilst im creating an invoice. here is the code i use for creating an invoice <?php include "includes/header.php"; ?> <div id="page_content"> <div id="sub_menu"></div> <div id="content"> <h1>Invoices</h1> <form name="form" method="POST" action="process_add_invoice.php"> <div id="add_client_box"> <h1> </h1> <table width="404" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="left">Select : </td> <td class="right"> <select name="id" style="vertical-align:middle; width:180px;"> <?php $result = mysql_query("SELECT * FROM clients ORDER BY company ASC"); while($row = mysql_fetch_array($result)) { echo "<option value=".$row['id'].">".$row['company']."</option>"; } ?> </select> </td> </tr> <tr> <td height="34" class="left"> </td> <td class="right"> </td> </tr> <tr> <td class="left">date : </td> <td class="right"><input class="field" type="text" name="date" /></td> </tr> </table> </div> <div id="add_client_box"> <h1> </h1> <table width="404" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="left">company : </td> <td class="right"> </td> </tr> <tr> <td class="left">invoice number : </td> <td class="right"><input class="field" type="text" name="invoice_number" /></td> </tr> <tr> <td class="left">title : </td> <td class="right"><input class="field" type="text" name="title" /></td> </tr> <tr> <td class="left">value : </td> <td class="right"><input class="field" type="text" name="value" /></td> </tr> <tr> <td class="left">status : </td> <td class="right"><input class="field" type="text" name="status" /></td> </tr> </table> </div> <div id="add_client_box"> <h1> </h1> <table width="404" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="left">pdf : </td> <td class="right"><input class="field" type="text" name="pdf" /></td> </tr> <tr> <td class="left"> </td> <td class="right"> </td> </tr> <tr> <td class="left"> </td> <td class="right"> </td> </tr> </table> </div> <div id="add_account_box"><input class="button" value="ADD INVOICE" type="submit" /></div> </form> </div> </div> <?php include "includes/footer.php"; ?> and here is the code which processes the invoice <?php include "includes/header.php"; ?> <div id="page_content"> <div id="sub_menu"></div> <div id="content"> <?php $id = $_POST['id']; $date = $_POST['date']; $invoice_number = $_POST['invoice_number']; $title = $_POST['title']; $value = $_POST['value']; $pdf = $_POST['pdf']; $status = $_POST['status']; $query = "INSERT INTO `invoices`(`id`,`date`,`invoice_number`,`title`,`value`,`pdf`,`status`)VALUES('".$id."','".$date."','".$invoice_number."','".$title."','".$value."','".$pdf."','".$status."')"; mysql_query($query) or die(mysql_error()); echo "<center>"; echo "<h1>Adding Invoice to Database, Please Wait</h1>"; echo "<META HTTP-EQUIV=Refresh CONTENT='5; URL=invoices.php'> "; echo "</center>"; ?> </div> <?php include "includes/footer.php"; ?> any ideas how to add more data to the form without having multiple drop downs. all i need is the drop down to support both ID and Company name so that these 2 fields are passed into the invoice table. Cheers Link to comment https://forums.phpfreaks.com/topic/147713-using-dynamic-data-on-a-new-form-to-insert-data-into-a-different-table/ Share on other sites More sharing options...
phpdragon Posted March 3, 2009 Share Posted March 3, 2009 you could reload the page with your drop down box getting it to call the data of your ID or have a page that selects the user then goto a page that generates the invoice for that user, knowing the user id before you call the page means you can query for the rest and set them as variables or you can use ajax to call the data into the page after the dropdown select Link to comment https://forums.phpfreaks.com/topic/147713-using-dynamic-data-on-a-new-form-to-insert-data-into-a-different-table/#findComment-775390 Share on other sites More sharing options...
fbm Posted March 3, 2009 Author Share Posted March 3, 2009 would i need some form of Javascript to reload the page after selecting a client from the drop down box? I'm thinking about the second option having the first page set to select the client then pass it to the next page where the invoice is then created. If it is possible to do it on 1 pge with a reload happenign after a client is selected that would be better but dont want to get involved with Javascript just yet Cheers Link to comment https://forums.phpfreaks.com/topic/147713-using-dynamic-data-on-a-new-form-to-insert-data-into-a-different-table/#findComment-775491 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.