PHP Code Extraction?
<p>I have a php coding that contains a login form. Once you login the form then changes to show an account balance and displays a few panel links also. </p>

<p>The problem i am having is trying to extract the login form from this code to move the form to the top, which worked good but now it broke the tables and background of the webpage. The code is very long so i can only paste the images. How to extract the form with the balance info without breaking or changing the php code?</p>

<pre><code>        &lt;?php
       include 'wasudf.php';

       //
       // get session id
       //
       $SessionID = $_GET['SessionID'];

       if (!$SessionID)
          $SessionID = $_POST['SessionID'];

       if (!$SessionID)
           $SessionID = $_COOKIE['SessionID'];

       if (!$Function)
          $Function = $_GET['FunkShun'];

       if (!$Function)
          $Function = $_POST['FunkShun'];

       if (!$Function)
          $Function="Home";

         //
       // no session id = sign in for the first time **I WANT THIS FORM-FROM HERE TO**
       //
       if (!$SessionID)
          {
          echo '&lt;form action="' . $_SERVER['SCRIPT_NAME'] . '" method="post"&gt;';
          echo '&lt;input type="hidden" name="SessionID" value="new"&gt;&lt;/input&gt;';
          echo '&lt;table width=800 align=center&gt;';

          echo '   &lt;tr&gt;';
          echo '      &lt;td align=center&gt;';
          echo '         Account Number';
          echo '         &lt;br&gt;';
          echo '         &lt;input type="text" name="AccountNo" value="" size=10&gt;&lt;/input&gt;';
          echo '      &lt;td&gt;';
          echo '   &lt;/tr&gt;';

          echo '   &lt;tr&gt;';
          echo '      &lt;td align=center&gt;';
          echo '         Password';
          echo '         &lt;br&gt;';
          echo '         &lt;input type="password" name="Password" value="" size=10&gt;&lt;/input&gt;';
          echo '      &lt;td&gt;';
          echo '   &lt;/tr&gt;';

          echo '   &lt;tr&gt;';
          echo '      &lt;td align=center&gt;';
          echo '         &lt;br&gt;';
          echo '         &lt;a href="' . $_SERVER['SCRIPT_NAME'] . '?FunkShun=Winners"&gt;Winning Numbers&lt;/a&gt;';
          echo '      &lt;td&gt;';
          echo '   &lt;/tr&gt;';

          echo '   &lt;tr&gt;';
          echo '      &lt;td align=center&gt;';
          echo '         &lt;br&gt;';
          echo '         &lt;input type="submit" value="Log On"&gt;&lt;/input&gt;';
          echo '      &lt;td&gt;';
          echo '   &lt;/tr&gt;';
          echo '&lt;/table&gt;';
          echo '&lt;/form&gt;';

          return;
          }

        //
       // this is a new session - add to web session table
       //
       if ($SessionID == "new")
          {
          $AccountNo = check_input(strtoupper(trim($_POST['AccountNo'])));
          $Password = check_input(strtoupper(trim($_POST['Password'])));

          if (!$AccountNo)
             ExitLogOn("Invalid Account/Password");

          $rs=mysql_query("select * from accounts where code='$AccountNo' and password='$Password'",$db);
          $row=mysql_fetch_array($rs);

          if (!$row)
             ExitLogOn("Invalid Account/Password!");

          mysql_query("update system set nextsession = nextsession + 1",$db);

          $rs=mysql_query("select * from system",$db);
          $row=mysql_fetch_array($rs);

          $SessionID = $row['nextsession'];

          //
          // ensure this session does not exist already
          // also remove any sessions belonging to this account
          //    - ie account can only be logged on one workstation at any time
          //
          mysql_query("delete from websession where sessionid='$SessionID' or account='$AccountNo'",$db);

          $Expiry=strtotime("+1 hour");

          $xCommand = "insert into websession set ";
          $xCommand = $xCommand . "sessionid='$SessionID',";
          $xCommand = $xCommand . "ipaddress='" . $_SERVER['REMOTE_ADDR'] . "',";
          $xCommand = $xCommand . "account='$AccountNo',";
          $xCommand = $xCommand . "password='$Password',";
          $xCommand = $xCommand . "date='" . date('YmdHis',$Expiry) . "'";

          mysql_query($xCommand,$db);
          }

       $rs=mysql_query("select * from websession where sessionid='$SessionID'",$db);
       $row=mysql_fetch_array($rs);

       if (!$row)
          {
          mysql_query("delete from websession where sessionid='$SessionID'",$db);
          mysql_query("delete from elist where code='$SessionID'",$db);
          ExitLogOn("Session Expired");
          }

           if ($row['date'] &lt; date('YmdHis'))
          {
          mysql_query("delete from websession where sessionid='$SessionID'",$db);
          mysql_query("delete from elist where code='$SessionID'",$db);
          ExitLogOn("Session Expired!!");
          }

       $Expiry=strtotime("+1 hour");

       $xCommand = "update websession set ";
       $xCommand = $xCommand . "date='" . date('YmdHis',$Expiry) . "'";
       $xCommand = $xCommand . "where sessionid='$SessionID'";

       mysql_query($xCommand,$db);

       $AccountNo = $row['account'];
       $Password = $row['password'];
       $MiscData = $row['data'];

       $rs=mysql_query("select * from accounts where code='$AccountNo' and password='$Password'",$db);
       $row=mysql_fetch_array($rs);

       if (!$row)
          ExitLogOn("Invalid Account/Password!!");

       $Name = trim($row['name']);
       $Balance = $row['balance'];

       if ($Function == "Home")
          {
          echo '&lt;form action="' . $_SERVER['SCRIPT_NAME'] . '" method="post"&gt;';
          echo '&lt;input type="hidden" name="SessionID" value="' . $SessionID . '"&gt;&lt;/input&gt;';
          echo '&lt;table width=800 align=center&gt;';

          echo '   &lt;tr&gt;';
          echo '      &lt;td align=center colspan="4"&gt;';
          echo           $Name;
          echo '      &lt;/td&gt;';
          echo '   &lt;/tr&gt;';

          echo '   &lt;tr&gt;';
          echo '      &lt;td align=center colspan="4"&gt;';
          echo '         Current Balance $ ' . snumber($Balance,10);
          echo '      &lt;/td&gt;';
          echo '   &lt;/tr&gt;';

          echo '   &lt;tr&gt;';
          echo '      &lt;td align=center colspan="4"&gt;';
          echo '         &amp;nbsp';
          echo '      &lt;/td&gt;';
          echo '   &lt;/tr&gt;';

      echo '&lt;/table&gt;';
      echo '&lt;/form&gt;';
// TO HERE
</code></pre>
