JTapp Posted April 15, 2008 Share Posted April 15, 2008 I'm trying to make two forms work on one page. They are both comprehensive search forms - one returns results from two tables, the other returns results from three other tables. Does anybody have any suggestions or links for me.. I can only get one form to work. Thanks! Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted April 15, 2008 Share Posted April 15, 2008 why not have one form with a radio button asking the user what they wanna search, and in your script search the tables depending on what they select. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted April 15, 2008 Share Posted April 15, 2008 What problems are you having? "only one works" isn't a helpful description of the problem. <form action="script1.php" method="post"> ... <input type="submit" name="submit" value="Submit form one" /> </form> <form method="script2.php" method="post"> ... <input type="submit" name="submit" value="Submit form two" /> </form> Quote Link to comment Share on other sites More sharing options...
benphp Posted April 15, 2008 Share Posted April 15, 2008 Yeah, if your forms are written right, there should be no issue, unless you're trying to put a form inside a form or something. Show us your forms. Quote Link to comment Share on other sites More sharing options...
doni49 Posted April 15, 2008 Share Posted April 15, 2008 I'd have to agree with the radio button idea but if you really do want two separate forms, you could do the following: <form name=form1 action=destination.php method=post> <input type=text name=editbox1> <input type=submit name=frm1Submit> </form> <form name=form2 action=destination.php method=post> <input type=text name=editbox2> <input type=submit name=frm2Submit> </form> in this case, the action page is the same. You'd then have code in the action page that would check to see which submit button was pressed: if(isset($_POST['frm1Submit'){//process form1} if(isset($_POST['frm2Submit'){//process form2} Or you could change the forms to use two different action pages--depending on which button was pressed, a different page would come up. Quote Link to comment Share on other sites More sharing options...
JTapp Posted April 15, 2008 Author Share Posted April 15, 2008 Well, here is the code (it's immature because I'm new at this). The second form works, but the first form - with the methode list returns nothing - regardless of what search parameters I put. <form method="post" action="http://www.glflamason.org/NEWSITE/NEW2/lodgelocator/3results.php"; target="_blank"> <p class="style1"> </p> <p class="style1"><img src="ldgePhotos/lodgelocator.gif" alt="LodgeLocator" width="370" height="53"></p> <p class="style1"> </p> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td width="544" height="183"> <p align="center"> <select name="metode" size="6"> <option value="tblLodges.strLodgeName" selected>Name of Lodge</option> <option value="tblLodges.intLodgeNumber">Lodge Number</option> <option value="tblLodges.intDistrictID">District Lodge Is In</option> <option value="tblLodges.strLodgeMailingCity">City Lodge Is Located In</option> <option value="tblLodges.strLodgeMailingPostCode">Zip Code of Lodge Location</option> <option value="tblLodges.strLodgeCounty">Lodge Parish</option> </select> <span class="style9">Search Value:</span> <input name="search2" type="text" class="form" size="25"> </p> <p align="center"> </p> <div align="center"> <input type="submit" value="Click Here To Search Our Lodge Locator!!" name="GOTWO"> </p> </div></td> </tr> </table> <hr> </form></td> <p> </p> <table class="auto" width="811"> <tr> <td width="803" height="510" class="row2"> <table width="79%" height="58%"> <tr> <td height="245" bgcolor="#E9E7D8" valign="top"> <table cellpadding="0" cellspacing="0" border="2" style=" height:25%;" height="57%" width="102%"> <tr valign="top" bgcolor="#E9E7D8"> <td height="194" align="center" valign="middle" bordercolor="#666633"> <form method="post" action="http://www.glflamason.org/NEWSITE/NEW2/lodgelocator/5results.php"; target="_blank"> <p class="style1"><img src="ldgePhotos/districtdetails.gif" alt="distdetails" width="370" height="53"></p> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td bordercolor="#000000"> <p> </p> <p align="center"> <input type="hidden" name="metode" value="tblLodges.intDistrictID"/> </select> <p> </p> <p align="center"<span class="style9">Enter District Number:</span> <input name="search" type="text" class="form" size="5"> </p> <div align="center"> <input type="submit" value="Click Here To View District Details" name="Go"> </p> <p align="center"> </p></td> </tr> </table> </form></td> Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted April 15, 2008 Share Posted April 15, 2008 can we see your PHP code? Quote Link to comment Share on other sites More sharing options...
JTapp Posted April 15, 2008 Author Share Posted April 15, 2008 Here is the PHP code - again, I'm new.. be gentle with me on my sloppy code: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> </head> <body> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody> <tr> <td width="100%"><p align="center"><span class="style2"> Grand Lodge of Florida Lodge Locator</span><br /> </p></td> </tr> </tbody> </table> <center> </center> <center> <br /> <br /> <table border="1" cellpadding="4" cellspacing="0" width="86%"> <tbody> <tr> <td colspan="5" bgcolor="FFFF99" height="18"><center> <strong>Results Of Your Search </strong> </center></td> </tr> <tr> <td width="13%" height="18" align="center" bgcolor="FFFF99"><center> Lodge ID Number </center></td> <td width="19%" height="18" align="center" bgcolor="FFFF99"><center> Lodge Name </center></td> <td width="20%" align="center" bgcolor="FFFF99"> Click Button To View <strong>Lodge Details </strong></td> <td width="18%" height="18" align="center" bgcolor="FFFF99"><center> City </center></td> <td width="10%" height="18" align="center" bgcolor="FFFF99"><center> District Number </center></td> </tr> <?php $username = "username"; $password = "password"; $hostname = "localhost"; $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); $selected = mysql_select_db("database",$dbhandle) or die("Could not select database"); $query = mysql_query("SELECT strLodgeName, intLodgeNumber, intDistrictID, strLodgeMailingCity, strLodgeMailingPostCode FROM tblLodges WHERE TRIM(LEADING '0' FROM $metode) = '$search' GROUP BY strLodgeName LIMIT 50"); while ($row = @mysql_fetch_array($query)) { echo "<tr bgcolor=\"#dddddd\"><td><center>"; echo $row["intLodgeNumber"]; echo "</center></td><td><center>"; echo $row["strLodgeName"]; echo "</center></td><td><center><span class=\"style2\">"; echo "<input name=\"submit\" type=\"button\" value=\"Lodge Details\" onclick=\"javascript:window.location='3view.php?id="; echo $row["intLodgeNumber"]; echo "'\" /></center></td>"; echo "</center></td><td><center>"; echo $row["strLodgeMailingCity"]; echo "</center></td><td><center>"; echo ltrim($row["intDistrictID"], '0'); }?> </tbody> </table> <br /> </center> </body> </html> Quote Link to comment Share on other sites More sharing options...
doni49 Posted April 15, 2008 Share Posted April 15, 2008 Try giving each form a different name. Even as simple as form1 and form2: <form name="form1" method="post" action="http://www.glflamason.org/NEWSITE/NEW2/lodgelocator/3results.php"; target="_blank"> <form name="form2" method="post" action="http://www.glflamason.org/NEWSITE/NEW2/lodgelocator/5results.php"; target="_blank"> Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted April 15, 2008 Share Posted April 15, 2008 Try cleaning up your html...there is unclosed tags everywhere and other mistakes that can interfere. Why is there a semi-colon in the form declaration? <form method="post" action="http://www.glflamason.org/NEWSITE/NEW2/lodgelocator/3results.php"; target="_blank"> There is a span in the middle of a paragraph tag: <p align="center"<span class="style9">Enter District Number:</span> Your html doesn't necessarily need to validate, but if you're having problems, it usually a good step to go back, clean up, and make sure that all your tags match up. Quote Link to comment Share on other sites More sharing options...
JTapp Posted April 15, 2008 Author Share Posted April 15, 2008 doni49 - I tried your suggestion.. but no go.. thanks though. Quote Link to comment Share on other sites More sharing options...
JTapp Posted April 15, 2008 Author Share Posted April 15, 2008 Hitman - I use Dreamweaver and cleaned it up via their "clean up html" option. 13 corrections were made. In addition, I tried your edits, but no go.... Quote Link to comment Share on other sites More sharing options...
doni49 Posted April 15, 2008 Share Posted April 15, 2008 It's quite possible that the HTML code is fine now but the PHP code doesn't output anything. Which form does NOT work? Can we see the code from the action script for THAT form? If possible only show the code that actually processes that form. Quote Link to comment Share on other sites More sharing options...
JTapp Posted April 15, 2008 Author Share Posted April 15, 2008 Here is my online testing page: http://www.glflamason.org/NEWSITE/NEW2/lodgelocator/5search.php The second form - closer to the bottom (District Details), works fine - use "6" if you want to try it out. The first form (Lodge Locater) DOES NOT WORK - parameters to try are: "Tuscan" for 'Name of Lodge' or "6" for 'District Lodge is In'. The first form is pointed to 3results.php and I posted the code earlier, but here it is: The code works fine when it is the only form on the page.... <?php $username = "username"; $password = "password"; $hostname = "localhost"; $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); $selected = mysql_select_db("database",$dbhandle) or die("Could not select database"); $query = mysql_query("SELECT strLodgeName, intLodgeNumber, intDistrictID, strLodgeMailingCity, strLodgeMailingPostCode FROM tblLodges WHERE TRIM(LEADING '0' FROM $metode) = '$search' GROUP BY strLodgeName LIMIT 50"); while ($row = @mysql_fetch_array($query)) { echo "<tr bgcolor=\"#dddddd\"><td><center>"; echo $row["intLodgeNumber"]; echo "</center></td><td><center>"; echo $row["strLodgeName"]; echo "</center></td><td><center><span class=\"style2\">"; echo "<input name=\"submit\" type=\"button\" value=\"Lodge Details\" onclick=\"javascript:window.location='3view.php?id="; echo $row["intLodgeNumber"]; echo "'\" /></center></td>"; echo "</center></td><td><center>"; echo $row["strLodgeMailingCity"]; echo "</center></td><td><center>"; echo ltrim($row["intDistrictID"], '0'); }?> Thanks for your time! Quote Link to comment Share on other sites More sharing options...
sasa Posted April 15, 2008 Share Posted April 15, 2008 the name of input field in your 1st form is search2 not search Quote Link to comment Share on other sites More sharing options...
JTapp Posted April 15, 2008 Author Share Posted April 15, 2008 search2 was the problem... Thank you very much!!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.