pass php variables to mysql database

Reply

Join Date: Jun 2008
Posts: 23
Reputation: forwardlookguy is an unknown quantity at this point 
Solved Threads: 0
forwardlookguy forwardlookguy is offline Offline
Newbie Poster

pass php variables to mysql database

 
0
  #1
Sep 5th, 2008
Hello, I have a problem that someone can hopefully help me with. I have a page where Make, Year and Model menus are dynamically created via mysql. Upon selection, the user presses submit and those values are fed to the database where the production numbers for say, a 1958 Plymouth Belvedere are displayed. The menus work fine. I just can't figure out how to feed the menu values into the database to display the production numbers.

Here's the code for the first page:
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3.  
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5. <head>
  6. <meta name="generator" content=
  7. "HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org" />
  8.  
  9. <title>Classic Decoder</title>
  10. <meta http-equiv="content-type" content="text/html; charset=us-ascii" />
  11. </head>
  12.  
  13. <body>
  14.  
  15. <link rel="stylesheet" href="includes/background.css" type="text/css" />
  16. <?php REQUIRE("includes/header.css"); ?>
  17.  
  18. <script language="javascript" type="text/javascript">
  19. <!--
  20.  
  21. function TEXT(txt) {
  22. window.status = txt;
  23. }
  24. // -->
  25. </script>
  26.  
  27. <script type="text/javascript">
  28. function AjaxFunction(id)
  29. {
  30. var httpxml;
  31. try
  32. {
  33. // Firefox, Opera 8.0+, Safari
  34. httpxml=new XMLHttpRequest();
  35. }
  36. catch (e)
  37. {
  38. // Internet Explorer
  39. try
  40. {
  41. httpxml=new ActiveXObject("Msxml2.XMLHTTP");
  42. }
  43. catch (e)
  44. {
  45. try
  46. {
  47. httpxml=new ActiveXObject("Microsoft.XMLHTTP");
  48. }
  49. catch (e)
  50. {
  51. alert("Your browser does not support AJAX!");
  52. return FALSE;
  53. }
  54. }
  55. }
  56. function stateck()
  57. {
  58. if(httpxml.readyState==4)
  59. {
  60. document.getElementById("Makesid").innerHTML=httpxml.responseText;
  61.  
  62. }
  63. }
  64. var url="dd.php";
  65. url=url+"?id="+id;
  66. url=url+"&sid="+Math.random();
  67. httpxml.onreadystatechange=stateck;
  68. httpxml.open("GET",url,TRUE);
  69. httpxml.send(NULL);
  70. }
  71. </script>
  72.  
  73. <p>
  74.  
  75.  
  76. <form name="selection">
  77. Please SELECT a make: <select name=cat onchange="AjaxFunction(this.value);">
  78. <option value=''>Select One</option>
  79.  
  80. <?php
  81.  
  82.  
  83. REQUIRE "includes/dbconnect.php";// connection to database
  84. $q=mysql_query("select * from Makes order by name");
  85. while($n=mysql_fetch_array($q)){
  86. echo "<option value=$n[id]>$n[name]</option>";
  87.  
  88. }
  89.  
  90. ?>
  91. // Close database connection.
  92. mysql_close();
  93.  
  94. ?>
  95. </select>
  96.  
  97. <div id="Makesid"></div>
  98.  
  99. </form>
  100.  
  101. <p>
  102. <form action="productionfigures.php" method="post">
  103. <input type="Submit" value="Submit" name="Submit">
  104. </p>
  105.  
  106.  
  107. <hr />
  108.  
  109. Note: The Rambler name was used FROM 1957 - 1969; meanwhile, the American Motors (AMC) name was incorporated IN 1966 AND used through 1980.
  110. </p>
  111. </body>
  112. </html>

And here's the code for the page where the second and third menus are populated:
  1. <html>
  2. <head>
  3.  
  4. <link rel="stylesheet" href="includes/background.css" type="text/css" />
  5. </head>
  6.  
  7. <body>
  8. <p>
  9.  
  10. the YEAR:
  11.  
  12.  
  13. <?php
  14.  
  15. $id=$_GET['id'];
  16. REQUIRE "includes/dbconnect.php";
  17. $q=mysql_query("select distinct yearname from Years where id='$id' order by yearname");
  18. echo mysql_error();
  19. echo "<select name=subcat>";
  20. while($nt=mysql_fetch_array($q)){
  21. echo "<option value='$nt[id]'>$nt[yearname]</option>";
  22.  
  23. }
  24. echo "</select>";
  25.  
  26. ?>
  27.  
  28. <br />
  29. <br />
  30.  
  31. AND the model:
  32.  
  33. <?php
  34.  
  35.  
  36. $id=$_GET['id'];
  37. REQUIRE "includes/dbconnect.php";
  38. $q=mysql_query("select * from Models where id='$id' order by modelname");
  39. echo mysql_error();
  40. echo "<select name=subcat>";
  41. while($nt=mysql_fetch_array($q)){
  42. echo "<option value='$nt[modelname]'>$nt[modelname]</option>";
  43.  
  44. }
  45. echo "</select>";
  46.  
  47. ?>
  48.  
  49. </p>
  50. </body>
  51. </html>

Could someone help me create the code for this? And would it go on the first page or the second?

Thanks a lot for any help,
Arthur Ash III
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC