php submit user email, mobile number in database

php submit user email, mobile number in database

In This tutorial will cover how PHP submit form data by POST method.

Introduction to the form

Two methods are used to submit form data in the database Post or Get.

POST data is submitted by a form and “posted” to the web server and get method submit data by url.

Step 1: Create a table in your database table name "user".

CREATE TABLE IF NOT EXISTS `user` (
  `user_id` int(11) NOT NULL,
  `user_name` varchar(50) NOT NULL,
  `user_mobile` varchar(15) NOT NULL,
  `user_mail` varchar(50) NOT NULL
);

Step 2: Create an php page name "index.php".

<!DOCTYPE html>
<html>
	<head>
		<title>php form data submit</title>
	
	</head>
	<body>
		<h1>php form data submit</h1>
		<form method="post" action="#">
			<input type="text" id="name" name="name" placeholder="name">
			<input type="number" id="mobile" name="mobile" placeholder="mobile">
			<input type="email" id="mail" name="email" placeholder="email">
			<button type="submit" name="submit">submit</button>
		</form>

	</body>
	
</html>

Step 3: use php code in with database connetion  "index.php".

		<?php
		// code for database connection----------------
		$db=mysql_connect('localhost','root','');
		$get_db = mysql_select_db('php_test_db');
		// close bd connection------------
		if(isset($_POST['submit'])){
		$name = $_POST['name'];
		$mobile = $_POST['mobile'];
		$mail = $_POST['email'];
		$query = mysql_query("INSERT INTO `user`(`user_name`, `user_mobile`, `user_mail`) VALUES ('$name','$mobile','$mail')");
		if($query){
		echo 'data save successfully..';
		}
		else
		{
		echo 'we get some problem while submiting data..';
		}
		}
		?>

The complete code of "index.php" now we with submit data through the same page.

<!DOCTYPE html>
<html>
	<head>
		<title>php form data submit</title>
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
		</script>
	</head>
	<body>
		<h1>php form data submit</h1>
		<form method="post" action="#">
			<input type="text" id="name" name="name" placeholder="name">
			<input type="number" id="mobile" name="mobile" placeholder="mobile">
			<input type="email" id="mail" name="email" placeholder="email">
			<button type="submit" name="submit">submit</button>
		</form>
		<?php
		// code for database connection----------------
		$db=mysql_connect('localhost','root','');
		$get_db = mysql_select_db('php_test_db');
		// close bd connection------------
		if(isset($_POST['submit'])){
		$name = $_POST['name'];
		$mobile = $_POST['mobile'];
		$mail = $_POST['email'];
		$query = mysql_query("INSERT INTO `user`(`user_name`, `user_mobile`, `user_mail`) VALUES ('$name','$mobile','$mail')");
		if($query){
		echo 'data save successfully..';
		}
		else
		{
		echo 'we get some problem while submiting data..';
		}
		}
		?>
	</body>
	
</html>

This is the complete working code for the same page submission. 


Comments / Answer

Leave a comment & ask question