SitePoint Sponsor |
|
User Tag List
Results 1 to 1 of 1
Thread: Search Form Problem
-
Jul 15, 2009, 11:12 #1
- Join Date
- Feb 2009
- Posts
- 8
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Search Form Problem
This is a simple form with one option. The option is populated with dynamic content. Works fine.
The s.php returns the entire db initially as it should.
I have been unable to get this s.php to first check if there was a category selected and return results accordingly.
If I change the form action to "s.php" it outputs the right xml based on the selected category.
I am stumped.
Any ideas?
Thanks.
Code:<html xmlns:spry="http://ns.adobe.com/spry"> <script src="../../../SpryAssets/xpath.js" type="text/javascript"></script> <script src="../../../SpryAssets/SpryData.js" type="text/javascript"></script> <script type="text/javascript"> <!-- var ds1 = new Spry.Data.XMLDataSet("s.php", "w/r"); //--> </script> <form class="form" action="<?=$_SERVER[PHP_SELF]?>" method="POST"> <table width="450" border="0"> <tr> <td>Category</td> <td><select name="cat" id="cid"> <option value="">All</option> <?php $con = mysql_connect('1', 'w', 'p'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("w"); $cate = @mysql_query("Select distinct category FROM cats"); if(!$cate) { exit('<p>Unable to get category list.</p>'); } while($cat= mysql_fetch_array($cate)) { $cid= $cat['category']; $cname =htmlspecialchars($cat['category']); echo "<option value ='$cid'>$cname</option>\n"; } ?> </select> </td> </tr> <tr> <td colspan="2"><input type="submit" name="button" id="button" value="Submit"></td> </tr> </table> </form> <div spry:region="ds1"> <table width="508"> <tr> <th>B</th> <th>C</th> <th>Cat</th> </tr> <tr spry:repeat="ds1"> <td>{b}</td> <td>{c}</td> <td>{cat}</td> </tr> </table> </div>
Code:<?php header("Content-type: text/xml" ); if(isset($_POST['submit'])); $con = mysql_connect('1', 'w', 'p'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("w"); $sql=" SELECT * FROM r WHERE st='A' AND ver='Y' "; $cid = $_POST['cat']; if($cid != '') {// Category is selected $sql .= "AND cat = '$cid'"; } $result = mysql_query($sql); $xml_output = "<?xml version=\"1.0\"?>\n"; $xml_output .= "<w>\n"; for($x = 0 ; $x < mysql_num_rows($result) ; $x++){ $row = mysql_fetch_assoc($result); $xml_output .= "\t<r>\n"; // Escaping illegal characters $row['b'] = str_replace("&", "&", $row['b']); $row['b'] = str_replace("<", "<", $row['b']); $row['b'] = str_replace(">", ">", $row['b']); $row['b'] = str_replace("\"", """, $row['b']); $xml_output .= "\t\t<b>" . $row['b'] . "</b>\n"; // Escaping illegal characters $row['c'] = str_replace("&", "&", $row['c']); $row['c'] = str_replace("<", "<", $row['c']); $row['c'] = str_replace(">", ">", $row['c']); $row['c'] = str_replace("\"", """, $row['c']); $xml_output .= "\t\t<c>" . $row['c'] . "</c>\n"; // Escaping illegal characters $row['cat'] = str_replace("&", "&", $row['cat']); $row['cat'] = str_replace("<", "<", $row['cat']); $row['cat'] = str_replace(">", ">", $row['cat']); $row['cat'] = str_replace("\"", """, $row['cat']); $xml_output .= "\t\t<cat>" . $row['cat'] . "</cat>\n"; $xml_output .= "\t</r>\n"; } $xml_output .= "</w>"; echo $xml_output; mysql_close($con); ?>
Bookmarks