unset Not working as expected

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Good afternoon group!  I have a simple addition form with add/cancel
buttons.  When the add button is clicked the action of the browser is sent
to a second processing page that verifies data and either adds the current
record or sends the client back to the addition form prepopulating it the
SESSION data.  This works great except when I try to unset the SESSION
variables their contents remain.  So if my user refreshes or navigates to
the page at a latter time with the same session id the form pre-populates,
which is undesirable.

Here is the Code. Thanks for any help.
Jeremy Schreckhise

Page 1 the addition page called lnu_add.php:
/***************************************************************************
************/
<?php

  session_start();


  $strProject  = $_SESSION['strProject'];
  $strHowMany  = $_SESSION['strHowMany'];
  $strNodes    = $_SESSION['strNodes'];
  $strOutput   = $_SESSION['strOutput'];
  $strStation  = $_SESSION['strStation'];
  $strRoutes   = $_SESSION['strRoutes'];
  $strSections = $_SESSION['strSections'];

  unset($_SESSION['strProject']);         // these never get unset
  unset($_SESSION['strHowMany']);
  unset($_SESSION['strNodes']);
  unset($_SESSION['strOutput']);
  unset($_SESSION['strStation']);
  unset($_SESSION['strRoutes']);
  unset($_SESSION['strSections']);

?>

<html>
    <head>
        <title>Add L&U: <?php echo $lnu ?> </title>
        <link rel="stylesheet" type="text/css" href="../homestyle.css">

       <script language="javascript">

          function Cancel_Click()
          {
               var strURL;
               strURL = "./lnu_brw.php";

               window.location = strURL;
          }


     </script>

    </head>
    <body>
     <script type="text/javascript" src="utilicis_menu.js">
     </script>

        <br><br>
        <table align="center" border=0>
         <tr>
          <td><font face="Verdana, Arial, Helvetica, sans-serif" size=4>
               <b>Add New L&U</b>
               </font>
          </td>
         </tr>
        </table>
        <br><br>

        <form name = "frmLNU" method = "post" action = '<?php echo
"./lnu_add2.php" ?>'>

 <table class='displaytable3'>
  <tr><td>

   <table class='heading' align=center>
    <tr>
     <td class='heading'>New L&U Project</td>
    </tr>
   </table><br>


 <table cellspacing=0 cellpadding=0>

  <tr><td class='rpthead'>Project Name:</td><td
class='rptspace'>&nbsp;</td><td><input type="textbox" size=20
name="txtProject" class="text" value="<?php echo $strProject; ?>"></td></tr>
  <tr><td class='rpthead'># of Routes:</td><td
class='rptspace'>&nbsp;</td><td><input type="textbox" size=20
name="txtHowMany" class="text" value="<?php echo $strHowMany; ?>"></td></tr>
  <tr><td class='rpthead'>Routes:</td><td
class='rptspace'>&nbsp;</td><td><input type="textbox" size=20
name="txtRoutes" class="text" value="<?php echo $strRoutes; ?>"></td></tr>
  <tr><td class='rpthead'>Nodes:</td><td
class='rptspace'>&nbsp;</td><td><input type="textbox" size=20
name="txtNodes" class="text" value="<?php echo $strNodes; ?>"></td></tr>
  <tr><td class='rpthead'>Sections:</td><td
class='rptspace'>&nbsp;</td><td><input type="textbox" size=20
name="txtSections" class="text" value="<?php echo $strSections;
?>"></td></tr>

 </table><br>

 <center><font size=4 color=blue><b>STATION LIST</b></font></center>

 <table class='displaytable4' align='center' cellspacing=0 cellpadding=0>
  <tr>
   <td><textarea rows=5 cols=90 name="tarStation" wrap="wrap"><?php echo
$strStation; ?></textarea></td>
  </tr>

 </table>

 <center><font size=4 color=blue><b>OUTPUT STATION LIST</b></font></center>

 <table class='displaytable4' align='center' cellspacing=0 cellpadding=0>
  <tr>
   <td><textarea rows=5 cols=90 name="tarOutput" wrap="wrap"><?php echo
$strOutput; ?></textarea></td>
  </tr>

 </table>

 <tr><td align=center><input type="submit" alt="Add LNU" border=0
name="cmdAdd" value="Add L&U" ><input type="button" name="cmdCancel"
onclick="Cancel_Click()" value="Cancel"></td></tr>
 </table>

       </form>

    </body>
</html>

/***************************************************************************
****************/
Page 2 the processing page called lnu_add2.php
/***************************************************************************
****************/
<?php

    //session stuff
    session_start();
    $username = $_SESSION['username'];
    $password = $_SESSION['password'];

    //timer
    set_time_limit(60);

    //VARS

    $dbconn     = odbc_connect("Utilicis_Nargon_ODBC",$username,$password) ;

    // error_reporting(0);

    $_SESSION['strProject']        = $_POST['txtProject'];
    $_SESSION['strHowMany']        = $_POST['txtHowMany'];
    $_SESSION['strNodes']          = $_POST['txtNodes'];
    $_SESSION['strOutput']         = $_POST['tarOutput'];
    $_SESSION['strRoutes']         = $_POST['txtRoutes'];
    $_SESSION['strSections']       = $_POST['txtSections'];
    $_SESSION['strStation']        = $_POST['tarStation'];

    $strProject  = $_SESSION['strProject'];
    $strHowMany  = $_SESSION['strHowMany'];
    $strNodes  = $_SESSION['strNodes'];
    $strOutput   = $_SESSION['strOutput'];
    $strRoutes   = $_SESSION['strRoutes'];
    $strSections = $_SESSION['strSections'];
    $strStation  = $_SESSION['strStation'];

    if(!is_numeric($strHowMany))
    {
   error_reporting(E_ALL^E_NOTICE);
   $strOut = "./lnu_add.php";
   print("<script language='JavaScript'>alert('Number of Routes Not
Numeric...Please Try Again'); window.location = '$strOut' </script>");
     die;
    }


    echo "$strProject $strHowMany";
    $dbconn     = odbc_connect("Utilicis_Nargon_ODBC",$username,$password) ;

    $strQry     = "SELECT * FROM lu WHERE project-name = '".$strProject."'";
    $rsTable    = odbc_do($dbconn, $strQry);

    if (odbc_fetch_row($rsTable))
    {

   error_reporting(E_ALL^E_NOTICE);
   $strOut = "./lnu_add.php";
   print("<script language='JavaScript'>alert('Project Already
Exist...Please Try Again'); window.location = '$strOut' </script>");
     die;
    }
    else
    {

  $strQry = "INSERT INTO lu
(how-many-routes,nodes,output-stations,project-name,routes,sections,station-
list)
VALUES($strHowMany,'".$strNodes."','".$strOutput."','".$strProject."','".$st
rRoutes."','".$strSections."','".$strStation."')";
  //$strQry = "INSERT INTO lu VALUES(1,'','','lnu100','','','')";
  $rsTable    = odbc_do($dbconn, $strQry);

        if($rsTable)
     {
      error_reporting(E_ALL^E_NOTICE);
      $strOut = "./lnu_brw2.php?lnu=".$strProject;

     unset($_SESSION['strProject']);
     unset($_SESSION['strHowMany']);
     unset($_SESSION['strNodes']);
     unset($_SESSION['strOutput']);
     unset($_SESSION['strStation']);
     unset($_SESSION['strRoutes']);
     unset($_SESSION['strSections']);

      print("<script language='JavaScript'>alert('Record Added');
window.location = '$strOut' </script>");


     }
     else
     {
         error_reporting(E_ALL^E_NOTICE);
         $strOut = "./lnu_add.php?lnu=".$strProject;
         print("<script language='JavaScript'>alert('Unable to Add
Record....Query Problem'); window.location = '$strOut' </script>");
         die;
     }


   }


?>

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux