PHP basic code to add data
<?php
$localhost="localhost";
$user="root";
$pass="";
$db="test";
$connect = mysqli_connect('localhost', 'root', '' ,'test');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Books</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="css/layout.css" type="text/css" />
</head>
<body id="top">
<div class="wrapper col0">
<div id="topline">
<p>Name: Books Website</p>
<br class="clear" />
</div>
</div>
<!-- ####################################################################################################### -->
<div class="wrapper">
<div id="header">
<div class="fl_left">
<h1><a href="index.html"><strong>T</strong>e<strong> s</strong>T</a></h1>
<p>Welcome to our website</p>
</div>
<br class="clear" />
</div>
</div>
<!-- ####################################################################################################### -->
<div class="wrapper col2">
<div id="topbar">
<div id="topnav">
<ul>
<li class="active"><a href="add.php">Add</a></li>
<li><a href="show.php">Show</a></li>
<li><a href="delete.php">Delete</a></li>
<li><a href="register.php">Register</a></li>
<li><a href="login.php">Login</a></li>
</ul>
</div>
<br class="clear" />
</div>
</div>
<!-- ####################################################################################################### -->
<div class="wrapper">
<b class="clear" />
</div>
<div id="hpage_cats">
<form method="POST" action="">
<label>Add Book Title: </label>
<input type="text" name="title" id="title"><br>
<label>Add Book Description: </label>
<textarea name="desc" id="desc"></textarea><br>
<button type="submit" name="add" id="add">Add</button>
</form>
</div>
</div>
<hr>
<!-- ####################################################################################################### -->
<?php
if(isset($_POST["add"]))
{
$sql="INSERT INTO `books`(`title`,`description`)VALUES('".$_POST['title']."', '".$_POST['desc']."')";
$result=mysqli_query($connect,$sql);
if($result)
echo "Your data has added";
else
echo "Try again";
}
?>
<!-- ####################################################################################################### -->
<div class="wrapper col8">
<div id="copyright">
<p class="fl_left">Copyright © 2021</p>
<br class="clear" />
</div>
</div>
</body>
</html>
No comments:
Post a Comment