"page Not Found" after submitting form to $_SERVER['PHP_SELF'] through Post Action

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael  Brennan-White

    "page Not Found" after submitting form to $_SERVER['PHP_SELF'] through Post Action

    If I submit my for using a get action the resulting page loads . If I
    use a post action I get an error page saying "The page cannot be
    found". I am calling the originating page!!! This happens in IE as
    well as FireFox.

    This code has been tested on a Win2003 server, IIS6, PHP 5.0.3, mySQL
    4.1.8 and it works fine.

    The problem server is a Win2k server, IIS5, PHP 5.0.4, mySQL 4.1.11.

    Any help would be greatly appreciated especially any tips for debugging
    the page.

    The lovely code for your review:

    <?php
    // start the session
    session_start() ;
    $_SESSION['CallingPage'] = $_SERVER['PHP_SELF'];
    $_SESSION['WhichComputer'] = $_SERVER['COMPUTERNAME'];
    $_SESSION['WhichServer'] = $_SERVER['SERVER_NAME'];
    $_SESSION['TheirIP'] = $_ENV['REMOTE_ADDR'];
    $_SESSION['TheirHost'] = $_ENV['REMOTE_HOST'];
    header("Cache-control: private"); //IE 6 Fix

    $Path2PHP = '../../lib/';

    $PageTitle = 'Treasury&nbsp;-- Abandoned Property Search';
    $PageHeader = 'Search For Abandoned Property';

    if (isset($_POST['submit'])) {
    $SectionHeader = 'Abandoned Property Search Results';
    }
    elseif (isset($_GET['page'])){
    $SectionHeader = 'Abandoned Property Search Results';
    }
    else{
    $SectionHeader = 'Search for Abandoned Property';
    }
    $IncludeMe = 'APHeader.php';
    include('APHead er.php');

    //Paginator
    if(!isset($_GET['page'])){
    $page = 1;
    } else {
    $page = $_GET['page'];
    }
    //echo 'Page Count: '.$_GET['page'];
    // Define the number of results per page
    $max_results = 10;

    // Figure out the limit for the query based
    // on the current page number.
    // Figure out the limit for the query based
    // on the current page number.
    $from = (($page * $max_results) - $max_results);
    ?>
    <link href="../css/nh.css" rel="stylesheet " type="text/css">
    <?php
    if (!isset($_POST['submit']) && (!isset($_GET['page']))) {
    ?>
    <p>&nbsp;</p>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

    <table>
    <tr><td><font color="#FF0000" >*</font> Last Name or Company:
    </td><td><input name="ln" size="30" type="text">
    Exact<input name="lnExact" type="checkbox" ></td></tr>
    <tr><td>First Name: </td><td><input name="fn" type="text"></td></tr>
    <tr><td><!-- <font color="#FF0000" >**</font> -->City:
    </td><td><input name="city" type="text"></td></tr>
    <tr><td><!-- <font color="#FF0000" >**</font> -->Company Holding
    Property: </td><td><input name="holder" type="text">
    </td></tr>
    </table>
    <input type="submit" name="submit" value="Search">
    <p><font color="#FF0000" >*</font> Required Field</p>
    <!-- <p><font color="#FF0000" >**</font> Not Implemented Yet</p>
    --> </form>
    <?php for($i = 1; $i <= 7; $i++){
    echo '<p>&nbsp;</p>';
    }
    ?>
    <?php

    } //if (!isset($_POST['submit'])) {
    else { //if (!isset($_POST['submit'])) {
    if (!isset($_GET['page'])) {
    $_SESSION['ln'] = $_POST['ln'];
    $_SESSION['fn'] = $_POST['fn'];
    $_SESSION['city'] = $_POST['city'];
    $_SESSION['refExact'] = $_POST['refExact'];
    $_SESSION['lnExact'] = $_POST['lnExact'];

    }

    $IncludeMe = 'db.php';
    include($Includ eMe);
    ?>
    <!-- Refine Search Table -->
    <br />
    <p><span class="SubSecti onLabel">Refine Search</span></p>
    <div name="RefineSea rch">
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <table width="100%" bgcolor="#39960 8" cellpadding="1" cellspacing="0" >
    <tr ><th width="30%" style="color:co rnsilk; font-size:12px">Last
    Name</th>
    <th width="25%" style="color:co rnsilk; font-size:12px">Firs t Name</th>
    <th width="25%" style="color:co rnsilk; font-size:12px">City </th>
    <th width="20%" style="color:co rnsilk; font-size:12px;">Exa ct
    <input name="refExact" type="checkbox" ></th></tr>
    <tr>
    <td><input type="text" name="ln" size="20" value="<?php echo
    $_SESSION['ln'] ?>"></td>
    <td><input type="text" name="fn" size="15" value="<?php echo
    $_SESSION['fn'] ?>"></td>
    <td><input type="text" name="city" size="15" value="<?php echo
    $_SESSION['city'] ?>"></td>
    <td><input type="submit" name="submit" value="Refine Search"></td>
    </tr>
    </table>
    </form>
    </div>
    <?php
    //Send a query to the server
    if (!isset($_SESSI ON['lnExact'])) {
    if (!isset($_SESSI ON['lnExact'])) {
    $_SESSION['strWhere']=" where lname like '%".$_SESSION['ln']."%' ";
    }
    else {
    $_SESSION['strWhere'] =" where lname = '".$_SESSION['ln']."' ";
    }
    } //if (!isset($_POST['lnExact'])) {
    else {
    $_SESSION['strWhere'] =" where lname = '".$_SESSION['ln']."' ";
    } //else {
    if (empty($_SESSIO N['fn'])) {
    $_SESSION['strFN']="";
    } //if (!isset($_POST['fn'])) {
    else {
    if (!isset($_SESSI ON['refExact'])) {
    $_SESSION['strFN']=" AND fname like '".$_SESSION['fn']."%' ";
    }
    else {
    $_SESSION['strFN']=" AND fname = '".$_SESSION['fn']."' ";
    }
    //$strFN=" AND fname like '%$fn%' ";
    } //else {

    if (empty($_SESSIO N['city'])) {
    $_SESSION['strCity']="";
    } //if (!isset($_POST['fn'])) {
    else {
    if (!isset($_SESSI ON['refExact'])) {
    $_SESSION['strCity']=" AND OWNERS.city like '".$_SESSION['city']."%'
    ";
    }
    else {
    $_SESSION['strCity']=" AND OWNERS.city = '".$_SESSION['city']."' ";
    }
    //$strCity=" AND OWNERS.city like '%$city%' ";
    } //else {
    If ($page == 1){
    $qcount = 'Select owners.ownerid from
    owners'.$_SESSI ON['strWhere'].$_SESSION['strFN'].$_SESSION['strCity'];
    //echo $qcount;
    $_SESSION['LastSQL'] = $qcount;
    $count=mysqli_q uery($mysqli,$q count);
    If ($count) {
    $_SESSION['counted'] = mysqli_num_rows ($count);
    //echo 'Counted: '.$counted;
    }
    }
    $SqlStr = "Select owners.Property ID,owners.lname , owners.fname, ";
    $SqlStr = $SqlStr."CONCAT (owners.lname,' ,',owners.fname ) AS nameo, ";
    $SqlStr = $SqlStr."owners .addr1, owners.city, owners.state, ";
    $SqlStr = $SqlStr."proper ties.amount, properties.prop type,
    holders.holder ";
    $SqlStr = $SqlStr."from owners inner join properties ";
    $SqlStr = $SqlStr."on owners.Property ID = properties.Prop ertyID ";
    $SqlStr = $SqlStr."INNER JOIN holders ";
    $SqlStr = $SqlStr."ON properties.hold erid = holders.holderi d ";
    $SqlStr=
    $SqlStr.$_SESSI ON['strWhere'].$_SESSION['strFN'].$_SESSION['strCity'];
    $SqlStr= $SqlStr." order by nameo asc limit ".$from.",".$ma x_results;
    $_SESSION['LastSQL'] = $SqlStr;
    //Get the resultset
    $result=mysqli_ query($mysqli, $SqlStr);
    if ($result){


    //$QueryRowcCount = 1;
    //print("Properti es : \n<br><br>");
    //Fetch the result of the query
    echo '<br /><br /><span class="SubSecti onLabel">Search
    Results</span><br>';

    $totalrows = mysqli_num_rows ($result);
    If ($totalrows > 0){
    echo '<table><tr><th >Name</th><th>Last Known Address</th>';
    echo '<th>Reported By</th><th>Amount</th></tr>';
    }
    else {
    echo '<p class="Subheade r">No Results to Display. Please refine your
    search</p>';
    }
    ?>

    <?php
    while($row=mysq li_fetch_assoc( $result)){
    if (!isset($QueryR owCount))
    {$QueryRowCount = 0;
    }
    if (!isset($BackCo lor))
    {$BackColor = 'white';
    }
    $QueryRowCount+ +;
    $Modulus = $totalrows % $QueryRowCount;

    if($BackColor !="white") { //if($BackColor !="white")
    $BackColor="whi te";
    } //if($BackColor !="white")
    else {
    $BackColor="cor nsilk";
    } //if($BackColor !="white")

    echo '<tr bgcolor="'.$Bac kColor.'"';
    echo " onMouseOver='";
    echo 'this.style.bac kground="cadetb lue"'."'";
    echo " onMouseOut='";
    echo 'this.style.bac kground="'.$Bac kColor.'"'."'>" ;


    echo '<td class="APtext"> ';
    //echo '<a href="ShowProp. php?PID='. $row['PropertyID'].'"';
    //echo ' onMouseOver="wi ndow.status='." 'Click the link to view
    information about this property'".';re turn true;" ';
    //echo 'onMouseOut="wi ndow.status='." 'New Hampshire State
    Treasury'".';re turn true;">';
    //echo '<acronym title="Click the Detail Button to view Property
    Information" class="noline"> ';

    echo '<div style="font-size:12px; cursor:pointer; color:#333300"
    onClick="window .location=';

    echo "'ShowProp.php? PID=";
    echo $row['PropertyID'];
    echo "'";
    echo '">';
    $displayname = $row['lname'];
    if (!empty($row['fname'])) {
    $displayname .= ", ".$row['fname'];
    }
    //$displayname = substr($display name,0,20);
    //echo $displayname. "<br /> ";
    echo '<acronym title="Click here to view Property Information"
    class="noline"> ';
    echo $displayname;
    echo '&nbsp;<img src="../../images/Mag1.jpg" alt="See More
    Information about this Property">';
    echo '</acronym>';
    //echo '<button
    onClick="window .location='."'S howProp.php?PID =".$row['PropertyID']."'".'">Details </button></acronym>';
    echo '</div>';
    //echo "</a>";
    echo "</td>";
    $OAddr = "";
    /* $checkvar = $row['addr1'];
    if (empty($checkva r)) {}
    //$OAddr = "";
    //}
    else { //if (empty($checkva r))
    $OAddr = trim($row['addr1'])."<br>";
    } //if (empty($checkva r)) */
    $OAddr = 'Not Disclosed<br />';
    $checkvar = $row['city'];
    if (empty($checkva r)) {}
    else { //else
    $OAddr = $OAddr.trim($ro w['city']);
    $checkvar = $row['state'];
    if (empty($checkva r)) {}
    else {
    $OAddr = $OAddr.', ';
    } //else {
    } //else
    $checkvar = $row['state'];
    if (empty($checkva r)) {}
    else {
    $OAddr = $OAddr.trim($ch eckvar);
    } //else {
    if (empty($OAddr)) {
    $OAddr = "Not Disclosed";
    } //if (empty($OAddr))
    echo '<td class="APtext"> '.$OAddr.'</td><td class="APtext"> ';
    //$holder = substr($row['holder'],0,20);
    $holder = $row['holder'];
    echo $holder.'</td><td class="APtext"> ';
    $propertytype = $row['proptype'];
    if ($propertytype == 'SC')
    {//A stock Property Type
    echo 'Stock Transaction';
    }
    else{
    $checkvar = $row['amount'];
    switch ($checkvar) {
    case ($checkvar <100):
    echo "Under $100";
    break;
    case ($checkvar >100):
    echo "Over $100";
    break;
    default:
    echo "Undisclose d";

    }
    }
    echo '</td></tr>';
    }
    //echo "<td>".$row['city']. "</td></tr>";
    } //while($row=mysq li_fetch_assoc( $result)){
    echo "</table>";
    // Figure out the total number of pages. Always round up using ceil()
    // Build Page Number Hyperlinks
    echo '<table width="100%"><t r><th align="center" width="100%">Se lect a
    Page</th></tr><tr><td align="center"> ';
    $total_pages = ceil($_SESSION['counted'] / $max_results);


    //echo "<center><b r />";
    // Build Previous Link

    if($page > 1){
    $prev = ($page - 1);
    echo "<a
    href=\"".$_SERV ER['PHP_SELF']."?page=$prev\" >Previous</a>&nbsp;";
    }

    for($i = $page; $i <= $total_pages; $i++){
    if(($page) == $i){
    echo "$i&nbsp;";
    } else {
    echo "<a
    href=\"".$_SERV ER['PHP_SELF']."?page=$i\">$i </a>&nbsp;";
    }
    if ($i > ($page + 5)) {
    break;
    }
    }
    // Build Next Link
    if($page < $total_pages){
    $next = ($page + 1);
    echo "<a href=\"".$_SERV ER['PHP_SELF']."?page=$next\" >Next>></a>";
    }
    echo "</td></tr></table>";
    //The mysqli_fetch_as soc() function is used to return an associative
    array representing the next row in the result set for the result
    represented by the result parameter, where each key in the array
    represents the name of one of the result set's columns.
    if ($totalrows > 5) {
    ?>
    <!-- Refine Search Table -->
    <br />
    <p><span class="SubSecti onLabel">Refine Search</span></p>
    <div name="RefineSea rch">
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <table width="100%" bgcolor="#39960 8" cellpadding="1" cellspacing="0" >
    <tr ><th width="30%" style="color:co rnsilk; font-size:12px">Last
    Name</th>
    <th width="25%" style="color:co rnsilk; font-size:12px">Firs t Name</th>
    <th width="25%" style="color:co rnsilk; font-size:12px">City </th>
    <th width="20%" style="color:co rnsilk; font-size:12px;">Exa ct
    <input name="refExact" type="checkbox" ></th></tr>
    <tr>
    <td><input type="text" name="ln" size="20" value="<?php echo $ln
    ?>"></td>
    <td><input type="text" name="fn" size="15" value="<?php echo $fn
    ?>"></td>
    <td><input type="text" name="city" size="15" value="<?php echo $city
    ?>"></td>
    <td><input type="submit" name="submit" value="Refine Search"></td>
    </tr>
    </table>
    </form>
    </div>
    <?php
    }

    $totalrows = 10;

    //Destroy the resultset and free the memory
    mysqli_free_res ult($result);
    } //if ($result){
    for($i = 10; $i <= 10; $i++){
    echo '<p>&nbsp;</p>';
    }
    //Close the connection
    if (isset($mysqli) ) {
    mysqli_close($m ysqli);
    } //if (!isset($mysqli )) {

    /* echo
    '<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>';
    */
    /* break;
    } */
    //} //if (!isset($_POST['submit'])) {
    include('APFoot er.htm');
    ?>

  • madmaster

    #2
    Re: &quot;page Not Found&quot; after submitting form to $_SERVER['PHP_SELF'] through Post Action

    Holla!

    I did not have the time to examine all the code but most of the servers
    I've published to are givint Page not Found or error 500 directly if
    some variables are missing or something is gone wrong with the script.

    A proposition is to examine more carefully the code or database 'cause
    as I said I didn't manage to check the code.

    Hope I helped! (daughtly ) :)

    Comment

    Working...