PHP link with SQL database

advertisements

New to PHP here. I'm working on a basic PHP project for university. I have a page with a list of patients. When you click on the patient it will take you to the patient page with more details of that patient.

I have a main patientDetails.php page which will display the details.

However I am a little puzzled. How do I get the "?Name.." part of the link to work. So how do I get the patientDetails page to load the specific patient details?

I have an index.php page which has the list of patients as below.

<td><a href="patientDetails.php?Name=Stuart">Stuart</a></td></tr><tr>    <td>2</td>
   <td><a href="patientDetails.php?Name=Fred">Fred</a></td></tr><tr>

In the PatientDetails page I have a select statement to gather details from the Database but not sure where else to go from here.

   $query = sprintf("select * from PHPEnrolment WHERE PatID = '$PatID' AND NAME     = '$Name' AND Email = '$Email'");
 $result = mysql_query($query, $link);
    if ($result) {
  while($row = mysql_fetch_array($result)) {

  }

As you can see above the database table with patients has the PatID, Name and Email field.

Thanks

PLEASE NOTE: This is a basic project that I am working on, so I am aware some of the features are outdated but I need to get it working with these features if possible.


You can get the url variables using $_GET. I see that you are passing only Name parameter in the url. Use the below code.

$name = $_GET['Name'];

$query = "select * from PHPEnrolment WHERE NAME = '$name'";
$result = mysql_query($query, $link);

if ($result) {
  while($row = mysql_fetch_array($result)) {
     // display details here
  }
}