Jump to content

search page


will35010

Recommended Posts

I'm having a problem with this script. I don't know if the problem is with my MySQL or with my lousy php. It's not giving an error but it's returning everything in that table when I searched using stuff that would only match a couple of records. Thanks for any help!  ;)

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
background-color: #FF33CC;
}
-->
</style></head>

<body>
<div align="center">
  <p><strong>Search for Existing Patient</strong></p>
  <form id="form1" name="pt_search" method="post" action="pt_search.php">
    <label>Last Name:
    <input type="text" name="lname" id="lname" />
</label>
<label>First Name:
    <input type="text" name="fname" id="fname" />
</label>
    <p>
      <input type="submit" name="submit" id="submit" value="Search" />
    </p>
  </form>
  <p> </p>
</div>
</body>
</html>
<?php
//code to search if a patient exist in the database

include('functions.php');

//if to prevent errors from showing
if(isset($_POST['submit'])){

//connection to mysqli db
require('db.php');

//to retrieve name and assign varible to it
$lname = $_POST['lname'];
$fname = $_POST['fname'];

//echo first part of table
echo "<center><table width='50%' border='1' bgcolor='lightblue'>
  <tr>
    <td width='24%'><b>Last Name</b></td>
    <td width='25%'><b>First Name</b></td>
    <td width='10%'><b>SEX</b></td>
    <td width='16%'><b>DOB</b></td>
    <td width='25%'><b>SS #</b></td>
  </tr>";

// Define your colors for the alternating rows
$color1 = "orange"; 
$color2 = "#CC00FF";

//set row count to 0
$row_count = 0;

//sql query
$query = mysqli_query($conn, "SELECT patientid, lname, fname, sex, dob, soc FROM patients WHERE lname LIKE '%$lname%' OR fname LIKE '%fname%' ORDER BY fname ASC");    

//loop and row method    
while($row = mysqli_fetch_array($query)){
    $row_color = ($row_count % 2) ? $color1 : $color2;
        echo "<tr>
    <td bgcolor=".$row_color."><a href='register.php?id=".$row['patientid']."'>".$row[lname]."</a></td>
    <td bgcolor=".$row_color.">".$row[fname]."</td>
    <td bgcolor=".$row_color.">".$row[sex]."</td>
    <td bgcolor=".$row_color.">".$row[dob]."   <b>(".GetAge($row[dob]).")</b></td>
    <td bgcolor=".$row_color.">".$row[soc]."</td>
  </tr>";

$row_count++;

    }
//close out the table
echo "</table></center>";    
    
echo "<center><a href='register.php?id=new'>Register New Patient</a></center>";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/188963-search-page/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.