Retrieving Records with PHP

We will now retrieve records from the Patient and Disease tables using PHP. We need to:

To illustrate the process, we will create a form where the user can enter the last name and then see the information for everyone with that last name.

Create a page lastname.php that sends the post values back to itself as shown:

<form id="form1" name="form1" method="post" action="lastname.php">
  <label>Last name
    <input type="text" name="Lastname" id="Lastname" />
  </label>
  <label>
    <input type="submit" name="button" id="button" value="Submit" />
  </label>
</form>

Next we will retrieve the matching records when the user presses submit:

$lastname=trim($lastname);
if(!empty($lastname)) {
  include($_SERVER[DOCUMENT_ROOT]."/data/connection.php");
  $sql='SELECT * FROM Patients WHERE lastname="'.$lastname.'" ORDER BY firstname';
  connect();
  $result=mysql_query($sql);
  mysql_close();
  while ($row=mysql_fetch_array($result)) { //retrieve each row
    extract($row); //breaks array up giving the names of fields from table
    echo $LastName.', '$FirstName.'<BR>'; //case sensitive: must match name of column in table
  }
}

INDEX, Retrieving Records with PHP, Add, Update and Delete, Missing Data, Join Tables, ALTER Table
Next lesson: FormsMAIN INDEX
EXAMPLES INDEX

Copyright © Zebra0.com
All rights reserved worldwide.

 
 

Retrieving Records with PHP