sam20e Posted November 11, 2014 Share Posted November 11, 2014 hi im new to these stuff and appreciate any help. im creating a simple form with 1 textbox and a search button. when the button is pressed a select query should run and check the mysql database and list that result on that same page. For example, lets say there is a textbox named Lastname, then the search button should search mysql and list down the last name matching that name. Form code : <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Search</title> </head> <body> <form action="post.php" method="GET"> <input type="text" name="query" /> <input type="submit" value="Search" /> </form> </body> </html> Any help? I need to show the result right bellow the button, and if no match found it should display an error : no match found thanks Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted November 11, 2014 Share Posted November 11, 2014 what code have you tried? we can really only help you with your code after you have actually made an attempt. php was originally created to do exactly what you are trying, process form data. there are probably two million examples posted on the web and a few 10's of thousands of books published on this subject for you to find and read to learn the basics. for the php mysql database library functions, you should be using prepared queries with either the PDO (preferred) or mysqli_ functions, because the msyql_ functions are obsolete. Quote Link to comment Share on other sites More sharing options...
sam20e Posted November 11, 2014 Author Share Posted November 11, 2014 (edited) Hi Thank you for the reply. This is what I have so far : HTML <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Search</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="style.css"/> </head> <body> <form action="post.php" method="GET"> <input type="text" name="text" /> <input type="submit" value="Search" /> </form> </body> </html> PHP <?php mysql_connect("localhost", "db", "pass") or die("Connection Failed"); mysql_select_db("db")or die("Connection Failed"); $text= $_POST['text']; $query = "select * from table where text= '$text'"; $result = mysql_query($query); while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "Name: ".$line['name']; echo " Age: ".$line['age']; echo "<br>\n"; } ?> It works great, but this is displaying result in a new window, i want the result to be shown bellow my button and also need to show no records found if the query result is null/na Edited November 11, 2014 by sam20e Quote Link to comment Share on other sites More sharing options...
boompa Posted November 12, 2014 Share Posted November 12, 2014 It works great, but this is displaying result in a new window, i want the result to be shown bellow my button and also need to show no records found if the query result is null/na Then you need to look into JavaScript and AJAX. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted November 12, 2014 Share Posted November 12, 2014 OR - resend the same form along WITH the results if you don't want to learn how to use JS/AJAX. Quote Link to comment 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.