•
•
•
•
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
![]() |
| |
•
•
Join Date: Oct 2007
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
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.
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.
php Syntax (Toggle Plain Text)
<?php if (isset($_POST['submitted'])){ if (isset($_POST['search'])){ $nm=$_POST['name']; $st=$_POST['status']; require_once ('mysql_connect.php'); $query="SELECT * FROM practice WHERE name LIKE '%$nm%' AND married LIKE '%$st%'"; $result=mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: ". mysql_error()); if(@mysql_num_rows($result) > 0) { echo '<h2>Search Results</h2>'; echo '<form name="results" method="POST" action="search.php">'; echo '<table border="1" cellspacing="0" width="320">'; 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>'; $x=0; while($row = mysql_fetch_assoc($result)) { $name[]=$row["name"]; $status[]=$row["married"]; echo '<tr>'; echo '<td> $name[$x] </td>'; echo '<td align="center"><select name="dropdown[]">'; echo '<option value="Yes" '; echo 'if ($status == "Yes"){echo "selected";}'; echo '>Yes</option>'; echo '<option value="No" '; echo 'if ($status == "No"){echo "selected";}'; echo '>No</option></select></td>'; echo '</tr>'; $x++; } echo '<td colspan="2" align="center"><input type="hidden" name="submitted" value="TRUE"><input type="submit" name="save" value="Save Changes"></td>'; echo '</table>'; echo '<br>Do another <a href="search.php">SEARCH</a>?'; echo '</form>'; }else{ echo '<h2>Search Results</h2>'; echo 'No results found. Do another <a href="search.php">SEARCH</a>?'; } }//closing for search if (isset($_POST['save'])){ $y = $_POST['dropdown']; foreach($y as $value){ echo "$value<br/>"; } }//closing for save }else{ ?> <h2>Search</h2> <form method="post" action="search.php"> <table border="0"> <tr> <td>Name</td> <td> <input type="text" name="name"> </td> </tr> <tr> <td>Status</td> <td> <input type="text" name="status"> </td> </tr> <tr> <td colspan="2" align="center"><input type="submit" name="search" value="Search"> <input type="hidden" name="submitted" value="TRUE"> </td> </tr> </table> </form> <?php } ?>
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- JS Dropdowns (JavaScript / DHTML / AJAX)
- Dropdowns close when cursor over link underneath (DaniWeb Community Feedback)
- In need of Menu over Frames (JavaScript / DHTML / AJAX)
- instant calculcated quote form (PHP)
- Safe Menu's ? (HTML and CSS)
- Unanswered threads (DaniWeb Community Feedback)
- Messenger webcam prob also Japanese XP internet stopped working (Web Browsers)
Other Threads in the PHP Forum
- Previous Thread: math equations
- Next Thread: Entering time in form MM:SS


Hybrid Mode