Here we will show how you can submit form without page refresh. For submitting form we use JQuery and Ajax with PHP and MySQl.
First we create a table where we store user input data.
Below we create a table user_data
--
-- Table structure for table `user_data`
--
CREATE TABLE `user_data` (
`id` int(11) NOT NULL,
`name` varchar(100) NOT NULL,
`email` varchar(100) NOT NULL,
`mobile` varchar(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Indexes for table `user_data`
--
ALTER TABLE `user_data`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT for table `user_data`
--
ALTER TABLE `user_data`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
COMMIT;
Now we create a connection file for built connect between PHP and MySQL Database . File name is “connection.php“ .
Now we create a form to take user inputs. create a file index.php.
Inflay.com | Submit a form without page refresh using jQuery Ajax PHP MySQL
Submit a form without page refresh using jQuery, Ajax, PHP and MySQL
USER LIST
Name Email Mobile
0)
{
while($row = mysqli_fetch_array($result))
{
?>
In above code we are taking data from user and show it in table format.
Below is code to submit user data via ajax to php file and take response from server without refresh page.
Now we need file to perform insert operation request send by ajax and return response to ajax.
So, we create a php file name “insert.php“.
0)
{
$result = "Done";
}
else
{
$result = "Fail";
}
echo json_encode($result);
}
?>
I hope this article helps you.
Thanks for visiting Inflay.com .