Formatting

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

 



Dear list -

When I run the following code, the results are preceded by at least one screen full of blank lines. I am showing you a large code block since I do not know where the error is:

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

        else
        {
            $sex = 'Female';
        }

     }
            $allowed_fields = array
('Site' => 's', 'MedRec' => 'i', 'Fname' => 's', 'Lname' => 's','Phone'=> 's', 'Height' => 'i', 'Sex' => 's',
                'Hx' => 's','Bday' => 's',  'Age' => 'i'
                );

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

// Configure the query and the acceptable params to put into the WHERE clause
            $sql12 = 'SELECT * FROM Intake3 WHERE 1';

           // Magically put everything together
            $types = '';
            $args = array();
            foreach( $allowed_fields as $k => $type )
            {
             if( !array_key_exists( $k, $allowed_fields ) )
                    continue;
                else
                {
                    if( ($_POST[$k]) != '')
                    {
$args[] = &$_POST[$k]; // Note the addition of the ampersand here
                        $types .= $type;
                        $sql12 .= " AND ($k = ?)";
                    }
                }
            }
            $stmt = mysqli_stmt_init($cxn);
            mysqli_stmt_prepare( $stmt, $sql12 );

            if( !$stmt )
                throw new Exception( 'Error preparing statement' );

// Put the statement and types variables at the front of the params to pass to mysqli_stmt_bind_param() array_unshift( $args, $stmt, $types ); // Note that I've moved this call. Apparently it doesn't pass back the result. I guess sometimes I just forget these things.

            // mysqli_stmt_bind_param()
            if( !call_user_func_array( 'mysqli_stmt_bind_param', $args ) )
            throw new Exception( 'Failed calling mysqli_stmt_bind_param' );

            if( !mysqli_stmt_execute( $stmt ) )
                throw new Exception( 'Error while executing statement' );

mysqli_stmt_bind_result( $stmt, $Site, $MedRec, $Fname, $Lname, $Phone, $Height, $Sex, $Hx, $Bday, $Age);




            if(count($errors_array) == 0)
            {


?>
<center><b>Search Results</b></center><br />
<center>
<!-- This is the block that prints about one screen full down bellow the Search Results header -->

<table border="4" cellpadding="5" cellspacing="55" rules="all" frame="box" style="table-layout: fixed;">
<tr class="heading">
<th>Site</th>
<th>Medical Record</th>
<th>First Name</th>
<th>Last Name</th>
<th>Phone</th>
<th>Height</th>
<th>Sex</th>
<th>History</th>
<th>Birthday</th>
<th>Age</th>
</tr>
</div>

<?php             $i = 0;
                do
                {
                    {
$vara2 = array(array($Site, $MedRec, $Fname, $Lname, $Phone, $Height, $Sex, $Hx, $Bday, $Age));

                        $vara2[$i][0]    = $Site;
                        $vara2[$i][1]    = $MedRec;
                        $vara2[$i][2]    = $Fname;
                        $vara2[$i][3]    = $Lname;
                        $vara2[$i][4]    = $Phone;
                        $vara2[$i][5]    = $Height;
                        $vara2[$i][6]    = $Sex;
                        $vara2[$i][7]    = $Hx;
                        $vara2[$i][8]    = $Bday;
                        $vara2[$i][9]    = $Age;

                        echo "<tr>\n";
                        $_SESSION['exe'] = 2;
?>
<td> <?php echo $vara2[$i][0]?> </td><br />
<td> <?php echo $vara2[$i][1]?> </td><br />
<td> <?php echo $vara2[$i][2]?> </td><br />
<td> <?php echo $vara2[$i][3]?> </td><br />
<td> <?php echo $vara2[$i][4]?> </td><br />
<td> <?php echo $vara2[$i][5]?> </td><br />
<td> <?php echo $vara2[$i][6]?> </td><br />
<td class="first-col"><?php echo $vara2[$i][7] ?></td><br />
<td> <?php echo $vara2[$i][8]?> </td><br />
<td> <?php echo $vara2[$i][9]?> </td><br />
<?php                     echo "</tr>\n";
                        $i = $i +1;

                    }
                } while (mysqli_stmt_fetch($stmt)); //end do-while
                    $imax = $i;
                    echo "</table>";
                    echo "</center>";
                    echo "</form>";

            }    //    end count($errors_array)

Help and advice, please

Ethan


--
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