Monday, 30 September 2013

delte row from MYSQL database based on variable ID using PHP button in FORM

delte row from MYSQL database based on variable ID using PHP button in FORM

I work on a website where you can add tags to a video. this screenshot
should give you an overview how the result should look like:
http://www.unistamp.ch/images/images.html
A video with comments is embeded and to the right there is an Iframe where
the detailed information for the comments on the timeline are accessed
from a MYSQL database. Here a screenshot of the video_comment table.
I want to delete a specific comment from the database based on his comment
ID. I tried this code but it doesnt work to pass the commentid by clicking
the X button:
<?php
include '../../../DB/MySql/connectVideoPhase.php';
//****** Delete Row in table
if(isset($_POST['X']))
{
$comment_id = $_POST['comment_id'];
//CHeck --> doesnt work
echo "<pre> commentid= ".$comment_id . "</pre> ";
$sql = "DELETE video_converted_comment ".
"WHERE commentid = \"".$comment_id."\" ;";
$retval = mysql_query( $sql);
if(! $retval )
{ die('Could not delete data: ' . mysql_error()); }
echo "Deleted data successfully\n";
}
//**************************************
//******* Get the comments
$video_id = $_REQUEST['VideoId'];
// for testing use a specific video ID
if (! $video_id) {
$video_id = '153fb143';
}
$sqlSelectComment = "Select * from
video_converted_comment WHERE videoid
='".$video_id."'";
$sqlComments = mysql_query($sqlSelectComment);
$i = mysql_num_rows($sqlSelectComment);
// *************************
//********* Fill Table
echo "
<table width=\"100\" border=\"1\" >
<tr>
<td width=\"25\"><b>start</b></td>
<td width=\"25\"><b>end</b></td>
<td width=\"75\"><b>Text</b></td>
<td width=\"5\"><b>X</b></td>
<td width=\"0\"><input type=\"hidden\"></td>
</tr>";
while ($comments = mysql_fetch_array($sqlComments))
{
echo "<tr><td>" .$comments['starttime'] ."</td>";
echo "<td>" .$comments['endtime'] ."</td>";
echo "<td>" .$comments['text'] ."</td>";
echo "<td> <form method=\"post\" action=\"".$_PHP_SELF ."\">
<input name=\"comment_id\" type=\"hidden\"
value=\"".$comments['id']."\">
<button name=\"X\" type=\"submit\"
value=\"".$comments['id']."\"> </td>
</form>";
}
echo "</table> ";
Any help on deleting/ adding comments to the DB based on a commentid using
PHP would be very appreciated! Would it be easier to do it with
javascript? The visualisation of the timeline below the video is done with
javascript.

No comments:

Post a Comment