php & MySQL practice (it worked!)

 

index.php

<html>
<head>
<title>Insert Form Data In MySQL Database UsingPHP </title>
</head>
<body>

<form action="insert.php" method="post">

Name : <input type="text" name="username">
<br/>
Email: <input type="text" name="email">
<br/>
<input type="submit" value="Insert">
</form>

</body>
</html>

****

insert.php

<?php

$con = mysqli_connect('localhost','root','');

if(!$con)
{
echo "Not connected to server";
}

if(!mysqli_select_db($con,'tutorial'))
{
echo 'Database Not Selected';
}

$Name = $_POST['username'];
$Email= $_POST['email'];

$sql="INSERT INTO person (Name,Email) VALUES ('$Name','$Email')";

if (!mysqli_query($con,$sql))
{
echo 'Not inserted';
}
else
{
echo 'Inserted';
}
/*
header("refresh:2; url=index.php");
*/
?>

 

Leave a Reply