deslyxia Posted June 3, 2012 Share Posted June 3, 2012 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()); Quote Link to comment https://forums.phpfreaks.com/topic/263599-return-php-query-result-to-webpage/ Share on other sites More sharing options...
smerny Posted June 3, 2012 Share Posted June 3, 2012 AJAX is if you need to get show the data without loading an entire page, your current code appears to load the psearch.php page upon submit. After your: $result = mysql_query($query) or die(mysql_error()); Put: $row = mysql_fetch_assoc($result); echo $row['FName']; This should give you an idea of how to do whatever you need to do. Quote Link to comment https://forums.phpfreaks.com/topic/263599-return-php-query-result-to-webpage/#findComment-1350946 Share on other sites More sharing options...
deslyxia Posted June 3, 2012 Author Share Posted June 3, 2012 AJAX is if you need to get show the data without loading an entire page, your current code appears to load the psearch.php page upon submit. psearch.php is just an external php file that i execute upon submit. It logs into the DB and performs a query. I somehow need to get my result set back onto the original page. How do i do this lol Quote Link to comment https://forums.phpfreaks.com/topic/263599-return-php-query-result-to-webpage/#findComment-1350948 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.