Good morning,
I am very new to php and this is my first post here. So here goes. I have an html page with a form where the user can type a first name and a last name. When submitted the php page will connect to and query my database returning all records that contain the strings from the form. Once the query executes I wrote a simple loop to echo the results… All of this to this point is working.
What I need to do is show the results formatted on an html page with buttons on each record that will allow the user to select the correct result if there is more than one.
[php]
<?php //Start session session_start(); //Include database connection details require_once('config.php'); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } //Sanitize the POST values $fname = clean($_POST['fname']); $lname = clean($_POST['lname']); //Query the Database $query = "select * from Patient where FName like '%$fname%' and LName like '%$lname%' "; $result = mysql_query($query) or die(mysql_error()); //Display Results while ($row = mysql_fetch_assoc($result)){ echo 'ID: '.$row['ID']; echo 'First Name: '.$row['FName']; echo '
Last Name: '.$row['LName']; echo '
'; } ?>
[/php]