STEP 1: HTML FORM
<body>
<h2>Data Form</h2>
<form action="info.php" method="post">//Data entered is redirected to 'info.php' page
Name:<input type="text" name="name" size="60" />
<br /> <br />
E-mail:<input type="text" name="email" size="60" />
<br /> <br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
STEP 2: PHP
<body>
<?php
//Connecting to a database
$servername="localhost";
$username="root";
$password="";
$dbname="info";
$connect=mysqli_connect("$servername","$username","$password","$dbname");
if (mysqli_connect_error())
{
die("Database connection failed: ". mysqli_connect_error());
}
else {
echo "Created connection successfully";
}
$info = "INSERT INTO userinfo (name, email)
VALUES ('$_POST[name]', '$_POST[email]')"; //to be inserted to the table called 'userinfo','name' and 'email' fields
if ($connect->query($user_info)==TRUE){
echo "Record added successfully";
}
else{
echo "Error: ".$user_info.$connect->error;
}
$connect-> close();
?>
<body>
<h2>Data Form</h2>
<form action="info.php" method="post">//Data entered is redirected to 'info.php' page
Name:<input type="text" name="name" size="60" />
<br /> <br />
E-mail:<input type="text" name="email" size="60" />
<br /> <br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
STEP 2: PHP
<body>
<?php
//Connecting to a database
$servername="localhost";
$username="root";
$password="";
$dbname="info";
$connect=mysqli_connect("$servername","$username","$password","$dbname");
if (mysqli_connect_error())
{
die("Database connection failed: ". mysqli_connect_error());
}
else {
echo "Created connection successfully";
}
$info = "INSERT INTO userinfo (name, email)
VALUES ('$_POST[name]', '$_POST[email]')"; //to be inserted to the table called 'userinfo','name' and 'email' fields
if ($connect->query($user_info)==TRUE){
echo "Record added successfully";
}
else{
echo "Error: ".$user_info.$connect->error;
}
$connect-> close();
?>
Comments
Post a Comment