User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,520 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,816 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 433 | Replies: 1
Reply
Join Date: Oct 2007
Posts: 2
Reputation: flushfire is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
flushfire flushfire is offline Offline
Newbie Poster

help me with my dropdowns...

  #1  
Oct 4th, 2007
I am trying to create a simple search page as practice for later use, where i search a table "practice" with fields "name" and "married". The user should then be able to search names, and upon submitting the page should display the names alongside the marital status. My problem is this: I want the status to be a dropdown (i tried checkboxes with much difficulty, failed) with the options yes and no, and then the user may be able to change the status by selecting from the dropdown and submitting.

Right now I am having a problem with assigning names to the dropdowns. To be able to relate them to the specific record in the database I should provide them with unique names right? But I used an array and when I post it always contains only one value, the first record. Here is my code. Please tell me what I'm doing wrong.
  1. <?php
  2. if (isset($_POST['submitted'])){
  3. if (isset($_POST['search'])){
  4. $nm=$_POST['name'];
  5. $st=$_POST['status'];
  6.  
  7. require_once ('mysql_connect.php');
  8. $query="SELECT * FROM practice WHERE name LIKE '%$nm%' AND married LIKE '%$st%'";
  9. $result=mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: ". mysql_error());
  10. if(@mysql_num_rows($result) > 0) {
  11.  
  12. echo '<h2>Search Results</h2>';
  13.  
  14. echo '<form name="results" method="POST" action="search.php">';
  15. echo '<table border="1" cellspacing="0" width="320">';
  16. echo '<tr bgcolor="#AAAAAA"><td align="center"><b><font color="#FFFFFF">Name</font></b></td><td align="center"><b><font color="#FFFFFF">Status</b></font></td></tr>';
  17.  
  18. $x=0;
  19. while($row = mysql_fetch_assoc($result)) {
  20.  
  21. $name[]=$row["name"];
  22. $status[]=$row["married"];
  23.  
  24. echo '<tr>';
  25. echo '<td> $name[$x] </td>';
  26. echo '<td align="center"><select name="dropdown[]">';
  27. echo '<option value="Yes" ';
  28. echo 'if ($status == "Yes"){echo "selected";}';
  29. echo '>Yes</option>';
  30. echo '<option value="No" ';
  31. echo 'if ($status == "No"){echo "selected";}';
  32. echo '>No</option></select></td>';
  33. echo '</tr>';
  34.  
  35. $x++;
  36. }
  37.  
  38. echo '<td colspan="2" align="center"><input type="hidden" name="submitted" value="TRUE"><input type="submit" name="save" value="Save Changes"></td>';
  39. echo '</table>';
  40. echo '<br>Do another <a href="search.php">SEARCH</a>?';
  41. echo '</form>';
  42.  
  43. }else{
  44. echo '<h2>Search Results</h2>';
  45. echo 'No results found. Do another <a href="search.php">SEARCH</a>?';
  46. }
  47. }//closing for search
  48. if (isset($_POST['save'])){
  49. $y = $_POST['dropdown'];
  50. foreach($y as $value){
  51. echo "$value<br/>";
  52. }
  53. }//closing for save
  54. }else{
  55. ?>
  56. <h2>Search</h2>
  57. <form method="post" action="search.php">
  58. <table border="0">
  59. <tr>
  60. <td>Name</td>
  61. <td>
  62. <input type="text" name="name">
  63. </td>
  64. </tr>
  65. <tr>
  66. <td>Status</td>
  67. <td>
  68. <input type="text" name="status">
  69. </td>
  70. </tr>
  71. <tr>
  72. <td colspan="2" align="center"><input type="submit" name="search" value="Search">
  73. <input type="hidden" name="submitted" value="TRUE">
  74. </td>
  75. </tr>
  76. </table>
  77. </form>
  78. <?php } ?>
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Posts: 2
Reputation: flushfire is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
flushfire flushfire is offline Offline
Newbie Poster

Re: help me with my dropdowns...

  #2  
Oct 4th, 2007
nevermind, i figured out what was wrong. the form was posting to a older version of the file, stupid me. lol. ill be back later when i run into more problems. xD
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 4:08 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC