By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,685 Members | 1,840 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,685 IT Pros & Developers. It's quick & easy.

PHP drop down list from MySQL database that will post to another table.

P: 1
I am very new to PHP and am looking for some help with a problem that I am facing. I currently have a form which post to a table in MySQL.

At the moment all the fields (apart from date) have to be inputted manually.

I would like to be able to have a number of the fields as selection drop down boxes, populated from seperate tables in the database. This will aid the user and provide uniform data that can easily be analysed.

I have spent days trying to find the exact code to perform this task, so would be grateful if somebody has an answer for me.

Here is the code so far, (the fields I wish to have as drop down boxes are Model, Repair Carried Out & Work Source:

Expand|Select|Wrap|Line Numbers
  1. <head>
  2. <script type="text/javascript" src="js/jquery.js" /></script>
  3.     <script type="text/javascript" src="js/jquery-ui.js" /></script>
  4. <script type="text/javascript" src="js/lisa.js" /></script>
  5.   <link href="css/jquery.css" media="screen" rel="stylesheet" type="text/css" />
  6.  
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  8. <title>Untitled Document</title>
  9. <style type="text/css">
  10. <!--
  11. body {
  12.     margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */
  13.     padding: 0;
  14.     text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
  15.     color: #000000;
  16.     font-family: Arial, Helvetica, sans-serif;
  17.     font-size: 100%;
  18.     background-color: #FFF;
  19. }
  20. .oneColFixCtrHdr #container {
  21.     width: 780px;  /* using 20px less than a full 800px width allows for browser chrome and avoids a horizontal scroll bar */
  22.     background: #FFFFFF;
  23.     margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */
  24.     border: 1px solid #000000;
  25.     text-align: left; /* this overrides the text-align: center on the body element. */
  26. }
  27. .oneColFixCtrHdr #header {
  28.     padding: 0 10px 0 20px;  /* this padding matches the left alignment of the elements in the divs that appear beneath it. If an image is used in the #header instead of text, you may want to remove the padding. */
  29.     background-color: #FFF;
  30. }
  31. .oneColFixCtrHdr #header h1 {
  32.     margin: 0; /* zeroing the margin of the last element in the #header div will avoid margin collapse - an unexplainable space between divs. If the div has a border around it, this is not necessary as that also avoids the margin collapse */
  33.     padding: 10px 0; /* using padding instead of margin will allow you to keep the element away from the edges of the div */
  34. }
  35. .oneColFixCtrHdr #mainContent {
  36.     padding: 0 20px; /* remember that padding is the space inside the div box and margin is the space outside the div box */
  37.     background: #FFFFFF;
  38.     text-align: right;
  39. }
  40. .oneColFixCtrHdr #footer {
  41.     padding: 0 10px;
  42.     background-color: #FFF;
  43. }
  44. .oneColFixCtrHdr #footer p {
  45.     margin: 0; /* zeroing the margins of the first element in the footer will avoid the possibility of margin collapse - a space between divs */
  46.     padding: 10px 0; /* padding on this element will create space, just as the the margin would have, without the margin collapse issue */
  47. }
  48. -->
  49. </style>
  50.  
  51.  
  52. </head>
  53.  
  54. <body class="oneColFixCtrHdr">
  55.  
  56. <div id="container">
  57.   <div id="header">
  58.     <h1>Header</h1>
  59.   <!-- end #header --></div>
  60.   <div id="mainContent">
  61.     <form method="POST" action="download_pdf.php" name="input" onSubmit="return validate()">
  62.      <table width="70%" border="0" align="center">
  63.        <tr>
  64.          <td>Owners Name</td>
  65.          <td><input type="text" name="Owners_Name" /></td>
  66.        </tr>
  67.        <tr>
  68.          <td>Model </td>
  69.          <td><input type="text" name="Model" /></td>
  70.        </tr>
  71.        <tr>
  72.          <td>Reg No. </td>
  73.          <td><input type="text" name="Reg_No" /></td>
  74.        </tr>
  75.        <tr>
  76.          <td>Mileage </td>
  77.          <td><input type="text" name="Mileage" /></td>
  78.        </tr>
  79.        <tr>
  80.          <td>Repairs Carried Out </td>
  81.          <td><input type="text" name="Repairs_Carried_Out" /></td>
  82.        </tr>
  83.        <tr>
  84.          <td>Repair Date </td>
  85.          <td><input type="text" name="Repair_Date" id="Repair_Date" /></td>
  86.        </tr>
  87.        <tr>
  88.          <td>Invoice Number </td>
  89.          <td><input type="text" name="Invoice_Number" /></td>
  90.        </tr>
  91.        <tr>
  92.          <td>VIN (17 digits)</td>
  93.          <td><input type="text" name="VIN" /></td>
  94.        </tr>
  95.        <tr>
  96.          <td>Total Repair Cost </td>
  97.          <td><input type="text" name="Total_Repair_Cost" /></td>
  98.        </tr>
  99.        <tr>
  100.          <td>Paint Cost </td>
  101.          <td><input type="text" name="Paint_Cost" /></td>
  102.        </tr>
  103.        <tr>
  104.          <td>Labour Cost </td>
  105.          <td><input type="text" name="Labour_Cost" /></td>
  106.        </tr>
  107.        <tr>
  108.          <td>Parts Cost </td>
  109.          <td><input type="text" name="Parts_Cost" /></td>
  110.        </tr>
  111.        <tr>
  112.          <td>Work Source </td>
  113.          <td><input type="text" name="Work_Source" /></td>
  114.        </tr>
  115.      </table>
  116.      <br/>
  117.      <br/>
  118.       <input type="submit" value="Save" /></form> 
  119.  
  120.   <!-- end #mainContent --></div>
  121.   <div id="footer">
  122.     <p>Footer</p>
  123.   <!-- end #footer --></div>
  124. <!-- end #container --></div>
  125. </body>
  126. </html>
  127.  
May 5 '10 #1
Share this Question
Share on Google+
1 Reply


dlite922
Expert 100+
P: 1,584
Do you know how to connect and query a mysql DB from PHP?

If not click this: lmgtfy.com?q=PHP%20MySQL%20Tutorial

Let me know if you get stuck anywhere,






Dan
May 6 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.