Jump to content

Unable to play videos and delete selected items.


ak47

Recommended Posts

Hi all, 
1. I want to delete selected(checkbox) items from database(MySQL). Here I am not getting any error, but I couldn't do the delete function.
2. Wants to play videos in website. Here videos storing into folder and also into database, but cannot playin website.

I tried in many ways, but I couldn't. So, please help to make above mentioned functions workable. 

dashboard.php
<form method="post" enctype="multipart/form-data">
<input type="submit" name="delete" class="btn btn-primary" onclick="myFunction(id)" style="font-size: 15px; margin-left: 3em;" value="Delete" />
</form>
<div>
<?php
$query = mysqli_query($database, "SELECT * FROM video");
while($row = mysqli_fetch_assoc($query))
{
$id = $row['id'];
$name = $row['name'];
$url = "../uploads";
// $url = $row['url'];
$fileextensionvalue= $row['fileextension'];
echo "<span class='col-md-6'>
<div class='row'>
<div class='col-md-1'><label class='checkbox'><input style='margin-right:1em;' name='checkbox[<?php echo $id; ?>]' type='checkbox' id='checkbox[]' data-toggle='checkbox' /></label></div>
<div class='col-md-1'><a href='#' style='color:red;font-size:18px;'>$id</a></div>
<div class='col-md-10'><a href='#' style='color:red;font-size:18px;'>$name</a></div>
</div>
<center style='padding:25px;'><video width='320' preload='auto' controls><source src='$url' type='video/$fileextensionvalue;codecs='avc1.42E01E, mp4a.40.2, H.264, aac, FLAC, Opus, VP9, VP8, Vorbis''/></video></center>
</span>";
}
?>
</div>

<script type="text/javascript">
function myFunction(id)
{
var r=confirm("Are you sure to delete selected video/s ?");
if(r==true)
{
window.location.assign("deleteVideo.php?id=" + id);
}
}
</script>

deleteVideo.php
<?php
include '../database/database.php';
$sql = mysqli_query($database, "SELECT * FROM video WHERE id='$id'");
if(empty($_POST['delete']))
{
Print '<script>alert("Please choose file/s to delete.");</script>';
Print '<script>window.location.assign("dashboard.php");</script>';
}
else if(!empty($_POST['delete']))
{
foreach($_POST['checkbox'] as $id => $val)
{
if($val=='checked')
{
$query=mysqli_query("DELETE FROM video WHERE id = '".$id."'");
$result= mysqli_query($database, $query) or die("Invalid query");
}
}
}
?>

Link to comment
Share on other sites

(1) All form element in your current setup should appear in between <form> and </form>

(2) IF using $_POST! The idea is to set a value for each checkbox so when it is submitted it is sent as $_POST array with these values.

(4) IF using $_GET! THIS " window.location.assign("deleteVideo.php?id=" + id); " is a $_GET querystring, so ALL $_POST['...'] in 'deleteVideo.php' should be $_GET['...'] instead

(3) As these can be multiple values the value of name attribute, should reflect it will be an array of values as in "name='checkbox[]'" 

(4) The 'id' argument equals WHAT? in onclick="myFunction(id)", its just text or undefined variable?

(5) How can $id exist or be defined if it has not retrieved yet! $sql = mysqli_query($database, "SELECT * FROM video WHERE id='$id'");

(6) You need to make your mind up which to use $_GET or $_POST, if using the $_GET by using JavaScript to open this  page then empty($_POST['delete'] will never exist. IF sent through GET querystring you would have to use $_GET['..']; instead

(6) This if($val=='checked') will never be true, the $id will equal index value of array holding the value which current does not exist? as there is no value assigned to that checkbox.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...