menu manager using php with mysql
1.database name is: web
2.table name is: menu
3.columns are:
NAME
LINK
SEQUENCE
menumanager.php
<?php
$hostname="localhost";
$username="root";
$password="";
$db_name="web";
$conn=new mysqli($hostname,$username,$password,$db_name);
if($conn->connect_error)
{
die("connnection failed");
}
else
{
# echo"connected";
if (isset($_POST['save']))
{
if($_SERVER['REQUEST_METHOD']=="POST")
{
$sql3="select * from menu where SEQUENCE=?";
$qry3=$conn->prepare($sql3);
$qry3->bind_param("i",$_POST['seq']);
$qry3->execute();
$table=$qry3->get_result();
if ($table->num_rows>0)
{
echo"<script>alert('this sequence number is already acquired');</script>";
}
else
{
$qry3->close();
$sql1="insert into menu (NAME,LINK,SEQUENCE) values(?,?,?)";
$qry1=$conn->prepare($sql1);
$qry1->bind_param("ssi",$_POST['link_name'],$_POST['url'],$_POST['seq']);
$qry1->execute();
echo"<script>alert('inserted');</script>";
$qry1->close();
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<h1>link</h1>
<form class="container" method="post">
<div class="form-group">
<label>link name</label>
<input type="text" name="link_name" class="form-control">
</div>
<div class="form-group">
<label>url</label>
<input type="text" name="url" class="form-control">
</div>
<div class="form-group">
<label>SEQUENCE</label>
<input type="NUMBER" name="seq" class="form-control">
</div>
<input type="submit" name="save" class="btn btn-default">
</form>
<?php
$sql="select * from menu";
$qry=$conn->prepare($sql);
$qry->execute();
$table=$qry->get_result();
?>
<table class="table table-stripped table-hover">
<tr>
<th>name</th>
<th>url</th>
<th>sequence</th>
<th>update</th>
<th>delete</th>
<?php
while($row=$table->fetch_assoc())
{
?>
<tr>
<td><?php echo $row['NAME']; ?> </td>
<td><?php echo $row['LINK']; ?></td>
<td><?php echo $row['SEQUENCE']; ?></td>
<td><a href="" class="btn btn-info">update</a></td>
<td><a href="delete.php?delid=<?php echo $row['ID'];?>" class="btn btn-danger" >delete</a></td>
<td></td>
</tr>
<?php
}
$qry->close();
}
$conn->close();
?>
<script type="text/javascript">
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
</table>
</body>
</html>
$hostname="localhost";
$username="root";
$password="";
$db_name="web";
$conn=new mysqli($hostname,$username,$password,$db_name);
if($conn->connect_error)
{
die("connnection failed");
}
else
{
# echo"connected";
if (isset($_GET['delid']))
{
$sql2="delete from menu where id=?";
$qry2=$conn->prepare($sql2);
$qry2->bind_param("i",$_GET['delid']);
$qry2->execute();
echo"<script>alert('deleted');</script>";
$qry2->close();
header('location:menu.php');
}
<?php
$hostname="localhost";
$username="root";
$password="";
$db_name="web";
$conn=new mysqli($hostname,$username,$password,$db_name);
if($conn->connect_error)
{
die("connnection failed");
}
else
{
echo"connected";
if ($_SERVER['REQUEST_METHOD']=="POST")
{
$n=$_POST['link_name'];
$link=$_POST['url'];
$s=$_POST['sequence'];
$sql="update menu set NAME=?,LINK=?,SEQUENCE=? where ID=?";
$qry=$conn->prepare($sql);
$qry->bind_param("ssii",$n,$link,$s,$_GET['updateid']);
$qry->execute();
echo"<script>alert('updated');</script>";
$qry->close();
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
</head>
<body>
<?php
$sql="select * from menu where ID=?";
$qry1=$conn->prepare($sql);
$qry1->bind_param("i",$_GET['updateid']);
$qry1->execute();
$table=$qry1->get_result();
$row=$table->fetch_assoc();
?>
<form method="post">
<label>name</label><br>
<input type="text" name="link_name" value="<?php echo $row['NAME'];?>"><br><br>
<label>url</label><br>
<input type="text" name="url" value="<?php echo $row['LINK'];?>"><br><br>
<label>sequence</label><br>
<input type="number" name="sequence" value="<?php echo $row['SEQUENCE'];?>"><br><br>
<input type="submit" name="save"><br><br>
</form>
<?php
$qry1->close();
$conn->close();
?>
</body>
</html>
0 Comments