You are on page 1of 8

view_video.

php

//display all video in a list langga. May inline edit kag delete button.

<!DOCTYPE html>

<html>

<head>

<title>Online-Video-Rental</title>

</head>

<style type="text/css">

th,tr{

width: 800px;

</style>

<body>

<?php

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

if (!$con) {

die('Unable to connect');

mysqli_select_db($con,"video-rental") or die('Unable to connect');

?>

<table width="700" border="1">

<th>
No.

</th>

<th>

Video ID

</th>

<th>

Video Title

</th>

<th>

Category

</th>

<th>Company</th>

<th>

Year Released

</th>

<th>

Action

</th>

<?php

$count=1;

$sel_query="Select * from video ORDER BY videoID desc;";

$result = mysqli_query($con,$sel_query);

while($row = mysqli_fetch_assoc($result)) { ?>


<tr>

<td align="center">

<?php echo $count; ?>

<td align="center">

<?php echo $row['videoID']; ?>

</td>

</td>

<td align="center">

<?php echo $row['title']; ?>

</td>

<td align="center">

<?php echo $row['category']; ?>

</td>

<td align="center">

<?php echo $row['company']; ?>

</td>

<td align="center">

<?php echo $row['yearReleased']; ?>

</td>

<td align="center">

<a href="edit.php?txtid=<?php echo $row['videoID']; ?>">Edit</a>&nbsp;<a


href="delete.php?txtid=<?php echo $row['videoID']; ?>">Delete</a>

</td>

</tr>
<?php $count++; }

mysqli_close($con);?>

</table>

</body>

</html>

edit.php

//maproceed sa edit form katumbas kang so_edit…ma edit ka na lang


dayon..

$con = mysqli_connect("localhost", "root","")or die(mysql_error());

mysqli_select_db($con,"video-rental" ) or die (mysql_error());

//generate and execute query

$vidId = $_REQUEST['txtid'];

$query ="SELECT * FROM video WHERE videoID ='$vidId'";

$result = mysqli_query($con, $query)

or die("Error in query:$query. ".mysql_error());

if(mysqli_num_rows($result)>0)

$row = mysqli_fetch_object($result);

?>
<table border ='1' width ='30%'>

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

<tr>

<td><b><font size ="3">Video ID</font></b></td>

<td><input size ="10" type ="text" name ="txtvidId" readonly="<?php echo


$row->videoID;?>" value="<?php echo $row->videoID;?>"></td>

</tr>

<tr>

<td><b><font size ="3">Title</font></b></td>

<td><input size ="20" type ="text" name ="txttitle" value ="<?php echo $row-
>title;?>"></td>

</tr>

<tr>

<td><b><font size ="3">Category</font></b></td>

<td><input size ="20" type ="text" name ="txtcategory" value ="<?php echo
$row->category;?>"></td>

</tr>

<tr>

<td><b><font size ="3">Company</font></b></td>

<td><input size ="20" type ="text" name ="txtcompany" value ="<?php echo
$row->category;?>"></td>

</tr>
<tr>

<td><b><font size ="3">Date Released</font></b></td>

<td><input size ="20" type ="text" name ="txtyear" value ="<?php echo $row-
>yearReleased;?>"></td>

</tr>

<tr>

<td colspan ="2">

<input type ="submit" name ="btnUpdate" value="Update">

</td>

</tr>

</form>

</table>

<?php

?>

<?php

mysqli_close($con);

?>

update.php
//syempre we have to update what we have edited langga..mayo tna sa database kay pwede
mo ma set sa tama ang pagkakamali mo ligad..ahahahh

<?php
if(!isset($_POST['txtvidId']) ||trim($_POST['txtvidId']==""))

die('NO Video ID.');

$videoid=$_POST['txtvidId'];

$title=$_POST['txttitle'];

$category=$_POST['txtcategory'];

$company=$_POST['txtcompany'];

$year=$_POST['txtyear'];

$con=mysqli_connect("localhost","root","")or die(mysqli_error());

mysqli_select_db($con,"video-rental") or die(mysqli_error());

$query="UPDATE video set videoID='$videoid',title='$title', category='$category',


company='$company' yearReleased='$year' WHERE videoID='$videoid'";

$result=mysqli_query($con, $query)or die("Error in query: $query.".mysqli_error());

Header("Location:view_video.php");

?>

delete.php
//automatic delete langga..wala na kuskos balungos..delete agad..recommended sa mabilis
na pag move on..

<?php
if(isset($_GET['txtid']) !=="")

$con = mysqli_connect("localhost","root" , "") or die(mysql_error());

mysqli_select_db($con,"video-rental") or die(mysql_error());

$delete = $_GET['txtid'];

$delete = mysqli_query($con,"DELETE FROM video WHERE videoID = '$delete'");

if($delete){

header("Location:view_video.php");

else{

echo 'Error';

?>

You might also like