PHP (Core & Framework)

How to Add User’s details after Registration

In this article we shall learn how to add details to your registered form. If you don’t know how to create a registration form you can learn that in my previous article.

To add details of a particular user you need to create another table.

For example

(you can refer the code  after explanation)

Here I have created a table “ myrecords “ using sql.

Syntax for creating a table:

$sql=

“insert into myrecords(user_id,type,title,startdate,enddate,postdate) 

values (‘$uid’,’$t’,’$ti’,’$sd’,’ed’,’pd’)”;

Now we need to run this query by passing connection file and the above query using the given function below:

“ mysqli_query($conn,$sql) “

If the function runs then the details will be added successfully, otherwise an error will be displayed.

CREATE TABLE IF NOT EXISTS `myrecords` (

  `item_id` int(11) NOT NULL,

  `user_id` int(50) NOT NULL,

  `type` int(2) NOT NULL,

  `title` text NOT NULL,

  `startdate` date NOT NULL,

  `enddate` date NOT NULL,

  `postdate` date NOT NULL

) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;

<!DOCTYPE html>

<html>
<head>
	<title>User Detail Form</title>
</head>
<body>
	<h1><u>USER DETAILS</u></h1><br><br>
	<?php
	include("connectins.php");

if(isset($_POST['submit']))
{
	$t=$_POST['type'];
	$ti=$_POST['title'];
	$sd=$_POST['s'];
	$ed=$_POST['e'];
	$pd=$_POST['p'];
	$uid=$_POST['user_id'];

	$sql="insert into myrecords(user_id,type,title,startdate,enddate,postdate) values ('$uid','$t','$ti','$sd','ed','pd')";

	if(mysqli_query($conn,$sql))
	{
		echo " Details Added Successfully !!!";
	}
	else
		echo "error:".$sql."<br>".mysqli_error($conn);
}
else
{
?>	
	<form method="post" name="myform" action="">
		
		
		
		
		TITLE:<input type="text" name="title"><br>
		START DATE:<input type="Date" name="s"><br>
		END DATE:<input type="Date" name="e"><br>
		POST DATE:<input type="Date" name="p"><br>
		<input type="submit" name="submit" value="Add">
	</form>

<?php
}
?>
</body>
</html>

Posted by : Rhythm Arya

Comment here

37 + = 46