👉Open xampp or wampp and start its server.
👉Create a database(in my case it is anjudb) and then table(in my case it is user) .
👉create a folder (in my case it is phpfolder) then create a file(in my case index.php) then copy paste te bellow code) and go to the url http://localhost/yourfoldername/.
👉This will help in clearing basic php logic .
<!-- //connection to database -->
<?php
error_reporting(0);
$host="localhost";
$user="root";
$password="";
$database="anjudb";
$con=mysqli_connect($host,$user,$password,$database);
if($con) {echo '<h1>Connected to MySQL</h1>';}
else {echo '<h1>MySQL Server is not connected</h1>';}
?>
<!-- //connection to database end -->
<!-- //form data insertion start -->
<?php
if($_POST["sub"])
{
$name=$_POST['firstname'];
$sql_query="INSERT INTO `user`(`name`) VALUES ('$name')";
$response= mysqli_query($con,$sql_query);
if( $response ){echo "Record Added Sucessfully";}
else{echo "Error";}
$con->close();
}
?>
<!-- //form data insertion end -->
<!-- //Html portion start -->
<html>
<head></head>
<body>
<form method="post" action="">
<input type="text" name="firstname">
<input type="submit" name="sub" value="submit" >
</form>
</body>
</html>
<!-- //Html portion End -->
0 Comments