I am basically working on a website using giant bomb's api, I have got search functionality on my site, but I am trying to get the users search to write to a mysql database without having to redirect to another php page. Does anyone have a suggestion that can help me out?
Input text box/button
<div align="center">
<form action="db.php" method="post">
<input type="text" id="gsearch" name="gsearch"></input>
<input type="button" id="gbutton" onclick="gamesearch()" value="search"></input>
</form>
</div>
PHP code writing to database.
<?php
// Connect to MySQL
require ('../finalconn.php'); // for iPage
//require ('../../../../mysqli_connect.php');
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="INSERT INTO searches (searched)
VALUES
('$_POST[searched]')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
$searched = $_POST["searched"];
mysqli_close($con);
?>