simple movie crud application in php without any css


database.php

-
-- Database: `caroline`
--

-- --------------------------------------------------------

--
-- Table structure for table `movie`
--

CREATE TABLE `movie` (
  `id` int(11) NOT NULL,
  `movie_name` varchar(250) NOT NULL,
  `star_cast` varchar(250) NOT NULL,
  `release_date` date NOT NULL,
  `ratings` double NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

config.php

<?php
$conn=mysqli_connect("localhost","root","","caroline");
if($conn)
{
}
else
{
die("connection failed");
}
?>

index.php

<!DOCTYPE html>
<html>
<head>
<title>movie website</title>
</head>
<body>
<div class="head">
<div class="logo">
movie website
</div>
<div class="nav">
<a href="add.php">add record</a>
</div>
</div>
<br>
<div class="container">
<table border="1">
<tr>
<th>no</th>
           <th>movie name</th>
           <th>cast</th>
           <th>release data</th>
           <th>ratings</th>
           <th>edit</th>
           <th>delete</th>
       </tr>
<?php
$i=0;
   include("config.php");
   $query="select * from movie";
   $data=mysqli_query($conn,$query);
   while($res=mysqli_fetch_assoc($data))
   {
    $i++;
    $id=$res["id"];
    $name=$res["movie_name"];
    $cast=$res["star_cast"];
    $relase=$res["release_date"];
    $rate=$res["ratings"];

echo "<tr>
<td>$i</td>
<td>$name</td>
<td>$cast</td>
<td>$relase</td>
<td>$rate</td>
<td><a href='edit.php?id=$id'>edit</td>
<td><a href='delete.php?id=$id'>delete</td>

</tr>";
   }

?>
</table>
</div>
</body>
</html>

add.php

<?php
include("config.php");
if(isset($_POST["submit"]))
{
$name=$_POST["name"];
$cast=$_POST["cast"];
$relase=$_POST["relase"];
$rate=$_POST["rate"];
$valid=1;
if(empty($name))
{
$name_msg="enter the movie name";
   
}
else if(empty($cast))
{
$cast_msg="enter the movie cast";
    
}
else if(empty($relase))
{
$relase_msg="enter the movie relase date";
  
}
else if(empty($rate))
{
$rate_msg="enter the movie rate";
    
}
else
{
$query="insert into movie(movie_name,star_cast,release_date,ratings) values('$name','$cast','$relase',$rate)";
$data=mysqli_query($conn,$query);
if($data)
{
$msg="data successfully inserted";

}
else
{
$msg="insert data failed";
}
}
}
?>

<!DOCTYPE html>
<html>
<head>
<title>add record</title>
</head>
<body>
<h1> add record</h1>
<a href="index.php">back to home</a>
<h1><?php if(isset($msg)){echo $msg;} ?></h1>
<form method="post">
<label>movie name</label>
<input type="text" name="name" value="<?php if(isset($name)){echo $name;}?>" ><span><?php if(isset($name_msg)){echo $name_msg;}?></span><br>
<label>star cast</label>
<input type="text" name="cast"value="<?php if(isset($cast)){echo $cast;}?>"><?php if(isset($cast_msg)){echo $cast_msg;}?></span><br>
<label>relase date</label>
<input type="date" name="relase"value="<?php if(isset($relase)){echo $relase;}?>"><?php if(isset($relase_msg)){echo $relase_msg;}?></span></br>
<label>ratings</label>
<input type="text" name="rate"value="<?php if(isset($rate)){echo $rate;}?>"><?php if(isset($rate_msg)){echo $rate_msg;}?></span><br>
<input type="submit" name="submit">
</form>

</form>
</body>
</html>

edit.php



<?php
include("config.php");
$id=$_REQUEST["id"];
 include("config.php");
   $query="select * from movie where id=$id";
   $data=mysqli_query($conn,$query);
    $res=mysqli_fetch_assoc($data);
   
   
    $ename=$res["movie_name"];
    $ecast=$res["star_cast"];
    $erelase=$res["release_date"];
    $erate=$res["ratings"];

if(isset($_POST["submit"]))
{
$name=$_POST["name"];
$cast=$_POST["cast"];
$relase=$_POST["relase"];
$rate=$_POST["rate"];
$valid=1;
if(empty($name))
{
$name_msg="enter the movie name";
   
}
else if(empty($cast))
{
$cast_msg="enter the movie cast";
    
}
else if(empty($relase))
{
$relase_msg="enter the movie relase date";
  
}
else if(empty($rate))
{
$rate_msg="enter the movie rate";
    
}
else
{
$query="update movie set movie_name='$name',star_cast='$cast',release_date='$relase',ratings=$rate where id=$id";
$data=mysqli_query($conn,$query);
if($data)
{
$msg="data successfully updated";

}
else
{
$msg="update data failed";
}
}
}
?>

<!DOCTYPE html>
<html>
<head>
<title>edit record</title>
</head>
<body>
<h1> edit record</h1>
<a href="index.php">back to home</a>
<h1><?php if(isset($msg)){echo $msg;} ?></h1>
<form method="post">
<label>movie name</label>
<input type="text" name="name" value="<?php if(isset($ename)){echo $ename;}?>" ><span><?php if(isset($name_msg)){echo $name_msg;}?></span><br>
<label>star cast</label>
<input type="text" name="cast"value="<?php if(isset($ecast)){echo $ecast;}?>"><?php if(isset($cast_msg)){echo $cast_msg;}?></span><br>
<label>relase date</label>
<input type="date" name="relase"value="<?php if(isset($erelase)){echo $erelase;}?>"><?php if(isset($relase_msg)){echo $relase_msg;}?></span></br>
<label>ratings</label>
<input type="text" name="rate"value="<?php if(isset($erate)){echo $erate;}?>"><?php if(isset($rate_msg)){echo $rate_msg;}?></span><br>
<input type="submit" name="submit">
</form>

</form>
</body>
</html>

delete.php


<?php
include("config.php");
$id=$_REQUEST["id"];

$query="delete  from movie where id=$id";
$data=mysqli_query($conn,$query);
if($data)
{

echo "delete succefully";
}
else
{
echo "not delete";
}
?>
<a href="index.php">back to home</a>

Post a Comment

If you have any doubts, Please let me know
Thanks!

Previous Post Next Post