Good Afternoon,
The issue i have is as follows. I have a form on my webpage, WHen the user clicks the submit button it excecutes an external php file which querys my database. I need to get the results of that query back into my main web page in a table. In researching this It seems that i need to use AJAX and possibly JQuery to do this ... but i have never used either so im lost.
Any help with this would be a great help as well as a great learning tool.
<form id="searchForm" name="searchForm" method="post" action="psearch.php" autocomplete="off">
<table width="300" border="0" align="center" cellpadding="2" cellspacing="0">
<tr>
<td width="112"><b>First Name</b></td>
<td width="188"><input name="fname" type="text" class="textfield" id="fname" /></td>
</tr>
<tr>
<td><b>Last Name</b></td>
<td><input name="lname" type="text" class="textfield" id="lname" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Search" /></td>
</tr>
</table>
</form>
PhP File
<?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());