Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. Select Department <font color='red'>*</font> </b> <?php
  2. $con=mysqli_connect("localhost","username","password","database_name");
  3. if (mysqli_connect_errno())
  4. {
  5. echo "Failed to connect to MySQL: " . mysqli_connect_error();
  6. }
  7. $result1 = mysqli_query($con,"SELECT * FROM dept");
  8. echo "<select>";
  9. while($drop = mysqli_fetch_array($result1))
  10. {
  11. echo "<option>" . $drop['department'] . "</option>";
  12. }
  13. echo "</select>";
  14. mysqli_close($con);
  15. ?>
  16.  
  17. <form class="appnitro" method="post" action="">
  18. <div class="form_description">
  19. <center><h2>NOMINATE ENTRY</h2></center>
  20. <p></p>
  21. </div><center>
  22. <b>Department &nbsp &nbsp </b> <?php
  23. $con=mysqli_connect("localhost","username","password","dbname");
  24. if (mysqli_connect_errno())
  25. {
  26. echo "Failed to connect to MySQL: " . mysqli_connect_error();
  27. }
  28. $result1 = mysqli_query($con,"SELECT * FROM dept");
  29. echo "<select name='department'>";
  30. while($drop = mysqli_fetch_array($result1))
  31. {
  32. echo "<option value='".$drop['department']."'>" . $drop['department'] . "</option>";
  33. }
  34. echo "</select>";
  35. mysqli_close($con);
  36. ?><p></center>
  37. <ul><center>
  38. <li class="buttons"><button type="submit" formaction="echo.php">Go</button></center></li>
  39. </ul>
  40. </form>
  41.  
  42. Department &nbsp &nbsp : <?php session_start(); $result=$_SESSION['department']; echo " ". $result; ?>
  43.  
  44. Select Department <font color='red'>*</font> </b>
  45.  
  46.  
  47. <form name ="form1" action="" method="post"> /* You can remove this if you already have a form */
  48. <?php
  49. $con=mysqli_connect("localhost","username","password","database_name"); // replace for you own.
  50. if (mysqli_connect_errno())
  51. {
  52. echo "Failed to connect to MySQL: " . mysqli_connect_error();
  53. }
  54. $result1 = mysqli_query($con,"SELECT * FROM dept");
  55. echo "<select name='department_name'>";
  56. while($drop = mysqli_fetch_array($result1))
  57. {
  58. echo "<option value='".$drop['department']."'>" . $drop['department'] . "</option>"; /* I would recommend changing the $drop['department'] in to the primary key from your table dept for example $drop['id'] */
  59. }
  60. echo "</select>";
  61. mysqli_close($con);
  62. ?>
  63. <input type="submit" value="Submit" name="submit">
  64. </form>
  65. <?php
  66. IF(isset($_POST['submit'])){
  67. echo "<b>Selected department: </b>".$_POST['department_name'] ;
  68. } /* This a test to see if you dropdown list works. */
  69. ?>
  70.  
  71. CREATE TABLE dept (
  72. id int auto_increment primary key,
  73. department varchar (30)
  74. );
  75.  
  76. INSERT INTO dept (department)
  77. VALUES ('department foo'), ('department foobar');
  78.  
  79. <form action="myfile.php" method="post">
  80. <select name="mydropdown">
  81. <option value="a">A</option>
  82. <option value="b">B</option>
  83. </select>
  84.  
  85. <input type="submit" value="Submit">
  86. </form>
  87.  
  88. <?php
  89.  
  90. $x = $_POST['mydropdown'];
  91.  
  92. ?>
  93.  
  94. <form class="appnitro" method="post" action="">
  95. <div class="form_description">
  96. <center><h2>NOMINATE ENTRY</h2></center>
  97. <p></p>
  98. </div><center>
  99. <b>Department &nbsp &nbsp </b> <?php
  100. $con=mysqli_connect("localhost","username","password","dbname");
  101. if (mysqli_connect_errno())
  102. {
  103. echo "Failed to connect to MySQL: " . mysqli_connect_error();
  104. }
  105. $result1 = mysqli_query($con,"SELECT * FROM dept");
  106. echo "<select name='department'>";
  107. while($drop = mysqli_fetch_array($result1))
  108. {
  109. echo "<option value='".$drop['department']."'>" . $drop['department'] . "</option>";
  110. }
  111. echo "</select>";
  112. mysqli_close($con);
  113. ?><p></center>
  114. <ul><center>
  115. <li class="buttons"><button type="submit" formaction="echo.php">Go</button></center>
  116. </li>
  117. </ul>
  118. </form>
  119.  
  120. <h3>Department &nbsp &nbsp : <?php $dept = $_POST['department']; echo " ". $dept; ?> </h3>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement