PHP search within Custom Page
-
We’ve created a PHP code that search and retrieves contents of a PDF file on our server. We’ve embedded that PHP code within a custom page on our WordPress site, but the search button no longer works. Instead of returning results of the search, we’re prompted to
index.php. Just not sure what we’re missing here…apologies in advance if the solution is obvious.Here is our php search code. Any help is appreciated.
[please read http://codex.wordpress.org/Forum_Welcome#Posting_Code for posting code]
<?php get_header (); if (have_posts ()) : while ( have_posts () ) : the_post (); // Get options for page // ----------------------------------------------------------- // title $pageTitle = get_the_title (); // breadcrumbs $hideBreadcrumbs = get_post_meta ( $post->ID, 'breadcrumbOff', true ); // sub-title $subTitle = get_post_meta ( $post->ID, 'subTitle', true ); // page icon $pageIcon = get_post_meta ( $post->ID, 'pageIcon', true ); if ($pageIcon == 'custom') { $pageIcon = '<img src="' . get_post_meta ( $post->ID, 'pageIcon_custom', true ) . '" width="128" height="128" alt="' . $pageTitle . '" />'; // Custom } elseif ($pageIcon == '') { $pageIcon = '<img src="' . $themePath . 'images/spacer.gif" width="128" height="128" alt="" />'; // Default } else { $pageIcon = '<img src="' . $pageIcon . '" width="128" height="128" alt="' . $pageTitle . '" />'; // Selected Icon } ?> <div id="PageOverlay"> <div id="PageOverlayContent"> <div class="contentArea"> <h1 class="pageTitle"><?php echo $pageTitle; ?></h1> </div> </div> </div> <!-- END id="PageOveraly" --> <div id="Showcase"> <div id="ShowcaseContent"> <div class="contentArea"> <h2 class="pageTagLine"><?php echo $subTitle; ?></h2> </div> </div> </div> <!-- END id="Showcase" --> <div id="MainPage"> <div id="MainPageContent"> <div class="contentArea"> <div class="two_third"> <div class="breadcrumbs" <?php if ($hideBreadcrumbs) { echo 'style="background: none;"'; } ?>> <?php if (!$hideBreadcrumbs) { show_breadcrumbs(); } ?> </div> <?php the_content('More Information...'); ?> <div id="abstract_search_page"> <?php $outputDisplay = ""; $paperNo = ""; $sessionNo = ""; $authors = ""; $keyword1 = ""; $keywordSearchCriteria = ""; $keyword2 = ""; $title = ""; $titleSearchCritieria = ""; $output_form = false; $years = ""; if (isset ( $_POST ['submit'] )) { $paperNo = trim ( $_POST ['txtPaperNo'] ); $sessionNo = trim ( $_POST ['txtSessionNo'] ); $authors = trim ( $_POST ['txtAuthors'] ); $keyword1 = trim ( $_POST ['txtKeyword1'] ); $keywordSearchCriteria = trim ( $_POST ['keyWordSearchCritiera'] ); $keyword2 = trim ( $_POST ['txtKeyword2'] ); $title = trim ( $_POST ['txtTitle'] ); $titleSearchCritieria = trim ( $_POST ['titleSearchCritieria'] ); $output_form = false; $years = ""; if (! empty ( $_POST ['lstYears'] )) { foreach ( $_POST ['lstYears'] as $items ) { $years .= $items . ", "; } $years = preg_replace ( "/, $/", "", $years ); } else { $years = ""; } if ((empty ( $paperNo )) && (empty ( $sessionNo )) && (empty ( $years )) && (empty ( $authors )) && (empty ( $keyword1 )) && (empty ( $keyword2 )) && (empty ( $title ))) { $outputDisplay = "<h3><font color=red>Please choose at least one search criteria</font></h3>"; $output_form = true; } if (! empty ( $titleSearchCritieria ) && (empty ( $title ))) { $outputDisplay = "<h3><font color=red>You must enter details for the Title before selecting the search criteria</font></h3>"; echo "<body onload=searchAbstracts.txtTitle.focus()>"; $output_form = true; } if ((! empty ( $keyword1 )) && (! empty ( $keyword2 )) && (empty ( $keywordSearchCriteria ))) { $outputDisplay = "<h3><font color=red>If you would like to search for two keywords, please and select a keyword search criteria..And/Or</font></h3>"; echo "<body onload=searchAbstracts.keyWordSearchCritiera.focus()>"; $output_form = true; } if ((empty ( $keyword1 )) && (! empty ( $keyword2 )) && (empty ( $keywordSearchCriteria ))) { $outputDisplay = "<h3><font color=red>Please enter a keyword in the first box and select a keyword search criteria..And/Or</font></h3>"; echo "<body onload=searchAbstracts.keyWordSearchCritiera.focus()>"; $output_form = true; } } else { $output_form = true; } if ($output_form) { ?> <form method="post" name="searchAbstracts" action="<?php echo $_SERVER['PHP_SELF']?>"> <p> <strong>Search Abstracts Online</strong> This page allows you to search for transactions by paper number, year, author's last name, keywords or any combination of fields within the selected form. You also have the ability to view all records by simply clicking the submit button. When searching by paper number, you must enter a 4 digit number. Example: Paper No. 1 enter 0001, Paper No. 23 enter 0023, Poster No. 549, enter 0549. If you are searching for a poster that ends with "A", you need to include "A" after the number. Example: Poster No. 688A enter 0688A. </p> <p> When searching by poster session, you must enter a 3 digit number. Example: Session 1 enter<strong>"001".</strong> Searching by nira session , you must enter a six characters. Example nira session one, enter <strong>"Nira001</strong>". Searching by poster session, you must enter eight characters. Example poster session one, enter <strong>"PS1--001</strong>". <strong> DISCLAIMER</strong> The abstract or collection of abstracts does not constitute an endorsement by the Orthopaedic Research Society (ORS) of the product, assay or information contained herein. No responsibility is assumed, and responsibility is hereby disclaimed, by the ORS for any injury and/or damage to persons or property as a matter of product liability, negligence or otherwise, or from any use or operation of methods, products, instructions or ideas presented in the abstracts. Independent verification of diagnosis and drug dosages should be made. Discussions, views and recommendations as to medical procedures, choice of drugs and drug dosages are the responsibilities of the authors. </p> <table width="100%"> <tr> <td width="29%" valign="top"><table width="100%"> <tr> <td width="26%" height="24" valign="top">Paper No</td> <td width="74%" valign="top"><input type="text" name="txtPaperNo" id="txtPaperNo" tabindex="1" /></td> </tr> <tr> <td height="24" valign="top">Session No</td> <td valign="top"><input type="text" name="txtSessionNo" id="txtSessionNo" tabindex="2" /></td> </tr> <tr> <td height="88" valign="top">Year:</td> <td valign="top"><select name="lstYears[]" size="5" multiple="multiple" tabindex="3"> <option value="2013">2013</option> <option value="2012">2012</option> <option value="2011">2011</option> <option value="2010">2010</option> <option value="2009">2009</option> <option value="2008">2008</option> <option value="2007">2007</option> <option value="2006">2006</option> <option value="2005">2005</option> <option value="2004">2004</option> <option value="2003">2003</option> <option value="2002">2002</option> <option value="2001">2001</option> <option value="2000">2000</option> <option value="1999">1999</option> </select></td> </tr> <tr> <td height="24" valign="top">Author:</td> <td valign="top"><input type="text" name="txtAuthors" id="txtAuthors" tabindex="4" /></td> </tr> <tr> <td height="46" valign="top">Title</td> <td valign="top"><select name="titleSearchCritieria" size="1" id="titleSearchCritieria" tabindex="5"> <option value="" selected="selected"></option> <option value="Begins With">Begins With</option> <option value="Ends With">Ends With</option> <option value="Includes">Includes</option> </select> <input type="text" name="txtTitle" id="txtTitle" tabindex="6" /></td> </tr> <tr> <td height="48" valign="top">Keyword</td> <td valign="top"><input type="text" name="txtKeyword1" id="txtKeyword1" tabindex="7" /> <select name="keyWordSearchCritiera" id="keyWordSearchCritiera"> <option value="" selected="selected"></option> <option value="And">And</option> <option value="Or">Or</option> </select> <input type="text" name="txtKeyword2" id="txtKeyword2" accesskey="9" tabindex="9" /></td> </tr> <tr> <td height="21" valign="top"> </td> <td valign="top"><input type="submit" name="submit" value="Search" /> <input type="reset" name="reset" value="Reset" tabindex="11" /></td> </tr> </table></td> <td width="100%" valign="top"><table width="98%"> <tr> <td valign="top"><?php echo $outputDisplay; ?></td> </tr> </table></td> </tr> </table> </form> <?php } else { $whereClause = array (); $lstYears = ""; $wherePart = ""; $sql_statement = "SELECT SessionNo, PaperNo, Year, Title, Authors, Keywords, Venue, Abstracts, TransactionsVolume FROM tbltransactions "; if ($paperNo) { $whereClause [] = " PaperNo = '" . $paperNo . "' "; } if ($sessionNo) { $whereClause [] = " SessionNo = '" . $sessionNo . "' "; } if ($years) { $whereClause [] = " Year IN ( $years ) "; } if ($authors) { $whereClause [] = " Authors LIKE '%$authors%' "; } if (($keyword1) && (! $keyword2) && (! $keywordSearchCriteria)) { $whereClause [] = " Keywords LIKE '%$keyword1%' "; } if (($keyword1) && ($keyword2) && ($keywordSearchCriteria)) { $whereClause [] = " Keywords LIKE '%$keyword1%' $keywordSearchCriteria Keywords LIKE '%$keyword2%' "; } if (($title) && (! $titleSearchCritieria)) { $whereClause [] = " Title LIKE '%$title%' "; } if (($title) && ($titleSearchCritieria)) { if ($titleSearchCritieria == "Begins With") { $whereClause [] = " Title LIKE '$title%' "; } if ($titleSearchCritieria == "Ends With") { $whereClause [] = " Title LIKE '%$title' "; } if ($titleSearchCritieria == "Includes") { $whereClause [] = " Title LIKE '%$title%' "; } } $db = mysql_connect ( 'localhost', 'popcorn_abstract', 'NE2I)1Tdzy0v' ) or die ( 'Error connection to MySQL server.' ); $setTaget = "_blank"; $dbname = 'popcorn_ors'; $orsSearchResult = mysql_select_db ( $dbname ); if ($orsSearchResult) { if (count ( $whereClause )) { } $sql_statement .= "WHERE " . implode ( 'AND', $whereClause ); $sql_statement .= "ORDER BY Year DESC, SessionNo ASC, PaperNo ASC "; $result = mysql_query ( $sql_statement ) or die ( 'Error querying the database' ); $outputDisplay = ""; $rowCount = 0; if (! $result) { $outputDisplay .= "<font color=red>MySQL No: " . mysql_errno (); $outputDisplay .= "MySQL Error: " . mysql_error (); $outputDisplay .= "SQL Statement: " . $sql_statement; $outputDisplay .= "MySQL Affected Rows: " . mysql_affected_rows () . "</font>"; } else { $numresults = mysql_num_rows ( $result ); if ($numresults != 0) { $outputDisplay .= '<table border=0 style="color:black;">'; for($i = 0; $i < $numresults; $i ++) { $rowCount ++; $row = mysql_fetch_array ( $result ); $SessionNo = $row ['SessionNo']; $PaperNo = $row ['PaperNo']; $Year = $row ['Year']; $Title = $row ['Title']; $Authors = $row ['Authors']; $Keywords = $row ['Keywords']; $Abstracts = $row ['Abstracts']; $Venue = $row ['Venue']; $TransactionVolume = $row ['TransactionsVolume']; if ($SessionNo != null) { $outputDisplay .= "<tr style=\"background-color:#F8F8F8;\">"; $outputDisplay .= "<td><stong>" . "Session" . "</td>"; $outputDisplay .= "<td>" . $SessionNo . "</td>"; $outputDisplay .= "</tr>"; $outputDisplay .= "<td><stong>" . "Paper" . "</td>"; $outputDisplay .= "<td>" . $PaperNo . "</td>"; $outputDisplay .= "</tr>"; } else { $outputDisplay .= "<tr style=\"background-color:#F8F8F8;\">"; $outputDisplay .= "<td><stong>" . "Paper" . "</td>"; $outputDisplay .= "<td>" . $PaperNo . "</td>"; $outputDisplay .= "</tr>"; } $outputDisplay .= "<td><stong>" . "Year" . "</td>"; $outputDisplay .= "<td>" . $Year . "</td>"; $outputDisplay .= "</tr>"; $outputDisplay .= "<td><stong>" . "Title" . "</td>"; $outputDisplay .= "<td>" . $Title . "</td>"; $outputDisplay .= "</tr>"; $outputDisplay .= "<td><stong>" . "Authors" . "</td>"; $outputDisplay .= "<td>" . $Authors . "</td>"; $outputDisplay .= "</tr>"; $outputDisplay .= "<td><stong>" . "Keywords" . "</td>"; $outputDisplay .= "<td>" . $Keywords . "</td>"; $outputDisplay .= "</tr>"; $outputDisplay .= "<td><stong>" . "Abstracts" . "</td>"; $outputDisplay .= "<td> <a href=" . $Abstracts . ">Abstracts</a></td>"; $outputDisplay .= "</tr>"; $outputDisplay .= "<td><stong>" . "Venue" . "</td>"; $outputDisplay .= "<td><stong>" . $Venue . "</td>"; $outputDisplay .= "</tr>"; $outputDisplay .= "<td><stong>" . "Transaction Volume" . "</td>"; $outputDisplay .= "<td>" . $TransactionVolume . "</td>"; $outputDisplay .= "</tr><td><td></tr></tr><td><td></tr>"; } $outputDisplay .= "</table>"; echo '<script type="text/javascript">document.forms[0].reset()</script>'; } else { } } } ?> <style type="text/css"> table { font-family: Verdana, Geneva, sans-serif; font-size: x-small; } </style> <form method="post" name="searchAbstracts" action="<?php echo $_SERVER['PHP_SELF']?>"> <p> <strong>Search Abstracts Online</strong> This page allows you to search for transactions by paper number, year, author's last name, keywords or any combination of fields within the selected form. You also have the ability to view all records by simply clicking the submit button. When searching by paper number, you must enter a 4 digit number. Example: Paper No. 1 enter 0001, Paper No. 23 enter 0023, Poster No. 549, enter 0549. If you are searching for a poster that ends with "A", you need to include "A" after the number. Example: Poster No. 688A enter 0688A. </p> <p> When searching by poster session, you must enter a 3 digit number. Example: Session 1 enter<strong>"001".</strong> Searching by nira session , you must enter a six characters. Example nira session one, enter <strong>"Nira001</strong>". Searching by poster session, you must enter eight characters. Example poster session one, enter <strong>"PS1--001</strong>". <strong> DISCLAIMER</strong> The abstract or collection of abstracts does not constitute an endorsement by the Orthopaedic Research Society (ORS) of the product, assay or information contained herein. No responsibility is assumed, and responsibility is hereby disclaimed, by the ORS for any injury and/or damage to persons or property as a matter of product liability, negligence or otherwise, or from any use or operation of methods, products, instructions or ideas presented in the abstracts. Independent verification of diagnosis and drug dosages should be made. Discussions, views and recommendations as to medical procedures, choice of drugs and drug dosages are the responsibilities of the authors. </p> <table width="100%"> <tr> <td width="10%" height="320" valign="top"><table width="24%"> <tr> <td width="31%" height="24" valign="top">Paper No</td> <td width="69%" valign="top"><input type="text" name="txtPaperNo" id="txtPaperNo" tabindex="1" /></td> </tr> <tr> <td height="24" valign="top">Session No</td> <td valign="top"><input type="text" name="txtSessionNo" id="txtSessionNo" tabindex="2" /></td> </tr> <tr> <td height="88" valign="top">Year:</td> <td valign="top"><select name="lstYears[]" size="5" multiple="multiple" tabindex="3"> <option value="2013">2013</option> <option value="2012">2012</option> <option value="2011">2011</option> <option value="2010">2010</option> <option value="2009">2009</option> <option value="2008">2008</option> <option value="2007">2007</option> <option value="2006">2006</option> <option value="2005">2005</option> <option value="2004">2004</option> <option value="2003">2003</option> <option value="2002">2002</option> <option value="2001">2001</option> <option value="2000">2000</option> <option value="1999">1999</option> </select></td> </tr> <tr> <td height="24" valign="top">Author:</td> <td valign="top"><input type="text" name="txtAuthors" id="txtAuthors" tabindex="4" /></td> </tr> <tr> <td height="46" valign="top">Title</td> <td valign="top"><select name="titleSearchCritieria" size="1" id="titleSearchCritieria" tabindex="5"> <option value="" selected="selected"></option> <option value="Begins With">Begins With</option> <option value="Ends With">Ends With</option> <option value="Includes">Includes</option> </select> <input type="text" name="txtTitle" id="txtTitle" tabindex="6" /></td> </tr> <tr> <td height="48" valign="top">Keyword</td> <td valign="top"><input type="text" name="txtKeyword1" id="txtKeyword1" tabindex="7" /> <select name="keyWordSearchCritiera" id="keyWordSearchCritiera"> <option value="" selected="selected"></option> <option value="And">And</option> <option value="Or">Or</option> </select> <input type="text" name="txtKeyword2" id="txtKeyword2" accesskey="9" tabindex="9" /></td> </tr> <tr> <td height="21" valign="top"> </td> <td valign="top"><input type="submit" name="submit" value="Search" /> <input type="reset" name="reset" value="Reset" tabindex="11" /></td> </tr> </table></td> </tr> <tr> <td> <td></td> <tr> <tr> <td> <td></td> <tr> <tr> <td height="320" colspan="2" valign="top"> <?php echo " <b>Number of Rows in Results: $rowCount </b> ";?> <?php echo $outputDisplay; ?></td> </tr> </table> </form> <?php } ?> </div> <!-- END id="abstract_search_page" --> <!-- Extras --> <div class="postFooter"> <?php edit_post_link('Edit','<p class="postEdit">','</p>'); ?> </div> <!-- End of Content --> <div class="clear"></div> </div> <!-- end <div class="two-thirds"> --> <?php endwhile ; endif; ?> <?php get_sidebar(); ?> <?php get_footer(); ?>
- The topic ‘PHP search within Custom Page’ is closed to new replies.