Boxerman Posted February 27, 2010 Share Posted February 27, 2010 Hi guys, How would i store the data of what has been searched? so say google search bar, you type phpfreaks and i want it to store on the database for say 30 days... how would i go about doing this? Quote Link to comment Share on other sites More sharing options...
visualazza Posted February 27, 2010 Share Posted February 27, 2010 i am only a beginner to php but i would suggest doing the following: very simple and untested some placement is wrong but the basis is there. <form name=input action=search.php method=POST> <input type=text name=q> <input type=submit name=submit value=Search> </form> <?php $q = $_POST['q']; //Include database connection details require_once ('config.php'); //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"); } $qry2 = "INSERT INTO table (column) VALUES ('$q')"; $result2 = mysql_query($qry2) or die(mysql_error()); $qry2 = "SELECT * FROM table WHERE column LIKE '%$q%'"; $row = mysql_fetch_array(mysql_query($qry)); $result2 = mysql_query($qry2) or die(mysql_error()); while ($row = mysql_fetch_array($result2)) { { { echo ("" . $row['column'] . ""); } } } ?> im not sure how you would go about storing it for a time period. 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.