[PHP] PHP & Database Problems -- Code Snippets - Any more Ideas?

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

 



I am sending this again to see if more ideas for solution of this problem are available.

Ethan
===========
Dear list -

Sorry for the attachment.  Here are code snippets ---

GET THE DATA FROM INTAKE3:

    function handle_data()
    {
       global $cxn;
       $query = "select * from Intake3 where  1";



       if(isset($_Request['Sex'])&& trim($_POST['Sex']) != '' )
       {
            if ($_REQUEST['Sex'] === "0")
            {
               $sex = 'Male';
            }
            else
            {
               $sex = 'Female';
            }
       }

    }

    $allowed_fields = array
( 'Site' =>$_POST['Site'], 'MedRec' => $_POST['MedRec'], 'Fname' => $_POST['Fname'], 'Lname' => $_POST['Lname'] , 'Phone' => $_POST['Phone'] , 'Sex' => $_POST['Sex'] , 'Height' => $_POST['Height'] );

    if(empty($allowed_fields))
    {
          echo "ouch";
    }

    $query = "select * from Intake3  where  1 ";

    foreach ( $allowed_fields as $key => $val )
    {
       if ( (($val != '')) )

    {
       $query .= " AND ($key  = '$val') ";
    }
       $result1 = mysqli_query($cxn, $query);
    }

    $num = mysqli_num_rows($result1);
    if(($num = mysqli_num_rows($result1)) == 0)
    {
?>
<br /><br /><center><b><p style="color: red; font-size:14pt;" >No Records Retrieved #1</center></b></style></p>
<?php
    exit();
    }

DISPLAY THE INPUT3 DATA:

>>> THIS SEEMS TO BE THE ROUTINE THAT IS FAILING <<<

    <center><b>Search Results</b></center><br />

<center><table border="4" cellpadding="5" cellspacing="55" rules="all" frame="box">
    <tr class=\"heading\">
    <th>Site</th>
    <th>Medical Record</th>
    <th>First Name</th>
    <th>Last Name</th>
    <th>Phone</td>
    <th>Height</td>
    <th>Sex</td>
    <th>History</td>
    </tr>

<?php

       while ($row1 = mysqli_fetch_array($result1, MYSQLI_BOTH))
       {
            print_r($_POST);
               global $MDRcheck;
               $n1++;
               echo "<br />n1 <br />";echo $n1;
            {
               if (($n1 > 2) && ($MDRcheck == $row1[1]))
               {
                    echo ">2==  ";
                    echo $MDRcheck;
                    echo "<td> $row1[0] </td>\n";
                    echo "<td> $row1[1] </td>\n";
                    echo "<td> $row1[2] </td>\n";
                    echo "<td> $row1[3] </td>\n";
                    echo "<td> $row1[4] </td>\n";
                    echo "<td> $row1[5] </td>\n";
                    echo "<td> $row1[6] </td>\n";
                    echo "<td> $row1[7] </td>\n";
                    echo "</tr>\n";
               }
               elseif (($n1 > 2) && ($MDRcheck != $row1[1]))
               {
                    echo ">2!=  ";

                    echo $MDRcheck;


                    continue;
               }
               elseif ($n1 == 2)
               {

                    define( "MDR" ,  $row1[1]);
                    echo "<br />row1 <br>";echo $row1[1];
                    echo "<tr>\n";

                    $_GLOBALS['mdr']= $row1[1];
                    $_POST['MedRec'] = $row1[1];
                    $MDRold = $_GLOBALS['mdr'];
                    echo "<td> $row1[0] </td>\n";
                    echo "<td> $row1[1] </td>\n";
                    echo "<td> $row1[2] </td>\n";
                    echo "<td> $row1[3] </td>\n";
                    echo "<td> $row1[4] </td>\n";
                    echo "<td> $row1[5] </td>\n";
                    echo "<td> $row1[6] </td>\n";
                    echo "<td> $row1[7] </td>\n";
                    echo "</tr>\n";
               }

            }
       }

?>

SELECT AND DISPLAY DATA FROM VISIT3 DATABASE

<?php
$query2 = "select * from Visit3 where 1 AND (Site = 'AA') AND (MedRec = $_GLOBALS[mdr])";
    $result2 = mysqli_query($cxn, $query2);
    $num = mysqli_num_rows($result2);


    global $finished;
    $finished = 0;


    while($row2 = mysqli_fetch_array($result2, MYSQLI_BOTH))
    {
       global $finished;
       echo "<tr>\n";
       echo "<td> $row2[0] </td>\n";
       echo "<td> $row2[1] </td>\n";
       echo "<td> $row2[2] </td>\n";
       echo "<td> $row2[3] </td>\n";
       echo "<td> $row2[4] </td>\n";
       echo "<td> $row2[5] </td>\n";
       echo "<td> $row2[6] </td>\n";
       echo "</tr>\n";

    }

echo "</table>";

ENTER MORE DATA:

    function More_Data()
    {
       $decision = 5;
?>

    Do you Wish to Enter More Data?
    <form method="post" action="">
<center><input type="radio" name="decision" value="1" />Yes <input type="radio" name="decision" value="0" />No</center><br />
    <center><input type="submit" value="Enter more Data" /></center>
    <input type="hidden" name="next_step" value="step10" />
     </form>

<?php
    } //>>>>>end function More_Data



    switch ( @$_POST[next_step] )
    {

       case "step10":
       {
            if (!isset($_POST['decision']))
            {
               $_POST['decision'] = 5;
            }

            if ($_POST['decision'] == 0)
            {
               exit();
            }
            if ($_POST['decision'] == 1)
            {
                 ;
       echo "<form method=\"post\" action=\"\">";
echo "<input type=\"hidden\" name=\"next_step\" value=\"step4\" />";
            echo "<enter><br />";
echo "Medical Record: &nbsp<input type=\"text\" name=\"MedRec\" value=\" $_GLOBALS[mdr]\" />"; echo "&nbsp&nbsp Weight: <input type=\"decimal\" name=\"Weight\" /></input><br /><br /><br /><br /> &nbsp&nbsp&nbsp&nbsp ";
            echo "Notes: <br /> ";
echo "<textarea style=\"overflow: scroll\"; cols=\"60\" rows=\"10\" wrap=\"hard\" name=\"Notes\" ></textarea> </input><p />";
            echo "<input type=\"submit\" value = \"Submit\"/><br /><br />";
            echo " <input type=hidden name=\"datain\" value='already'>";

            echo "<input type = \"reset\" /></center>";
       echo "</form>";


       }

    } /*  End Step10 */


    case "step4":
    {
       if (!isset($_POST['datain']))
       {
            $_POST['datain'] = 5;
       }



       if( $_POST['datain'] == "already")
       {

            date_default_timezone_set('America/New_York');


            $Date  = date('Ymd');
            $Date2 = date('d M Y');
$sql1 = "select MedRec, Height from Intake3 where (MedRec = $MDRold)";
            $result4 = mysqli_query($cxn, $sql1);
            $row4 = mysqli_fetch_array($result4, MYSQLI_BOTH);
            $Height = $row4[1];
            $Weight = $_POST['Weight'];
            $Notes  = $_POST['Notes'];

$sql5 = "select MedRec, Weight from Visit3 where (MedRec = $MDRold)";
            $result5 = mysqli_query($cxn, $sql5);
            $row5 = mysqli_fetch_array($result5, MYSQLI_BOTH);
            $BMI = ($Weight*703)/($Height*$Height);
            $BMI = round($BMI,1);

            $fptr1 = fopen("/home/ethan/PHP/HRecnumSite", "r+");
            fscanf($fptr1,"%d %s",$Num, $Site);
$sql2 = "INSERT INTO Visit3(Indx, Site, MedRec, Notes, Weight, BMI, Date) VALUES(null, '$Site', '$MDRold', '$Notes',
               $Weight, $BMI, '$Date')";

            $result6 = mysqli_query($cxn, $sql2);
            $MDRcheck = $MDRold;
            $row2 = mysqli_fetch_array($result6, MYSQLI_BOTH);

?>

?>

    <center>
<table border="4" cellpadding="5" cellspacing="55" rules="all" frame="box">
       <tr class=\"heading\">
       <th>Index</th>
       <th>Site</th>
       <th>Medical Record</th>
       <th>Notes</th>
       <th>Weight</th>
       <th>BMI</td>
       <th>Date</td>
       </tr>


<?php

       $sql3 = "select max(Indx) from Visit3";
       $result7 = mysqli_query($cxn, $sql3);
       $row7 = mysqli_fetch_array($result7, MYSQLI_BOTH);
       $Indx = $row7[0];

       echo "<tr>\n";
       echo "<td> $Indx </td>\n";
       echo "<td> $Site </td>\n";
       echo "<td> $_GLOBALS[mdr] </td>\n";
       echo "<td> $Notes </td>\n";
       echo "<td> $Weight </td>\n";
       echo "<td> $BMI </td>\n";
       echo "<td> $Date2 </td>\n";
       echo "</tr>\n";


       while($row8 = mysqli_fetch_array($result2, MYSQLI_BOTH))
       {
            global $finished;
            echo "<tr>\n";
            echo "<td> $row8[0] </td>\n";
            echo "<td> $_GLOBALS[mdr] </td>\n";
            echo "<td> $row8[2] </td>\n";
            echo "<td> $row8[3] </td>\n";
            echo "<td> $row8[4] </td>\n";
            echo "<td> $row8[5] </td>\n";
            echo "<td> $row8[6] </td>\n";
            echo "</tr>\n";
            echo "<br />row8<br />"; print_r($row8[1]);

       }
            echo "</table>";
            $flag = 1;

       }
    } /* end step4 */
} /* End Switch */

WELCOME SCREEN:

    function show_welcome()
    {

       $first_name = isset($_REQUEST["Fname"])  ? $_REQUEST["Fname"] : "";
       $last_name  = isset($_REQUEST["Lname"])  ? $_REQUEST["Lname"] : "";
       $medrec     = isset($_REQUEST["MedRec"]) ? $_REQUEST["MedRec"] : "";
       $phone      = isset($_REQUEST["Phone"])  ? $_REQUEST["Phone"] : "";
       $height     = isset($_REQUEST["Height"]) ? $_REQUEST["Height"] : "";

       echo "<form  method=\"post\">";
echo " <center>Site: <input type=\"text\" name=\"Site\" value=\"AA\" /></input>"; echo " Record Number: <input type=\"text\" name=\"MedRec\" value='", $medrec, "' /></input>"; echo " First Name: <input type=\"text\" name=\"Fname\" value='", $first_name, "' />"; echo " Last Name: <input type=\"text\" name=\"Lname\" value='", $last_name, "' /></input><br /><br />"; printf("Two Capital Letters\t\t\t Five Numbers\t\t\t\t Text - No Numbers\t\t\t Text - No Numbers\n\n\n"); echo " Phone: <input type=\"text\" name=\"Phone\" value='", $phone, "' /></input>"; echo " Height: <input type=\"decimal\" name=\"Height\" value='", $height, "' /></input><br /><br />";
       printf("XXX-XXX-XXXX\t\t\t    Inches\n\n");
echo " Male<input type=\"radio\" name=\"Sex\" value = \"Male\" checked>"; echo " Female<input type=\"radio\" name=\"Sex\" value = \"Female\" ><br /><br /><br />";
       echo " <input type=\"submit\"  /><br /><br />";
       echo " <input type=\"reset\" value = \"Clear Form\"  /></center>";
       echo " <input type=hidden name='welcome_already_seen'
          value='already_seen'>";

    }
?>

I hope this helps.

Ethan

























--
Ethan Rosenberg, PhD
Pres/CEO
Hygeia Biomedical Research, Inc
2 Cameo Ridge Road
Monsey, NY 10952
T: 845 352-3908
F: 845 352-7566
<mailto:erosenberg@xxxxxxxxxxxxxxxxxxxx>erosenberg@xxxxxxxxxxxxxxxxxxxx



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




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



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux