I am making the modification for the query and already add and everything but in modifying it does not work with 'id' that I put after putting the address of the modification page
this is the table
<!DOCTYPE html>
<html>
<head>
<title> TABLA </title>
</head>
<body>
<center>
<table bgcolor="#85C1E9" border="3">
<thead>
<tr>
<th colspan="1">Nuevo</th>
<th colspan="5">Lista de usuarios</th>
</tr>
</thead>
<tbody>
<tr>
<td>Id</td>
<td>Nombre</td>
<td>Apellido</td>
<td>Correo</td>
<td colspan="2"><center>Operaciones</center></td>
</tr>
<?php
include("conexiones.php");
$query="SELECT * FROM usuarios";
$resultado=$conexion->query($query);
while ($row=$resultado->fetch_assoc()) {
?>
<tr>
<td><?php echo $row['id'];?></td>
<td><?php echo $row['nombre'];?></td>
<td><?php echo $row['apellido'];?></td>
<td><?php echo $row['correo'];?></td>
<td><a href="modificar.php?id=<?php echo $row['id'];
?>">Modificar</a></td>
<td><a href="eliminar.php?id=<?php echo $row['id']; ?
>">Eliminar</a></td>
</tr>
<?php
}
?>
</tbody>
</table>
</center>
</body>
</html>
here the modify page
<!DOCTYPE html>
<html>
<head>
<title>Guardar</title>
</head>
<body>
<center>
<form action="guardar.php" method="POST" name="guardar"><br><br><br>
<?php
$id=$_REQUEST['id'];
include("conexiones.php");
$query="SELECT * FROM usuarios";
$resultado=$conexion->query($query);
$row=$resultado->fetch_assoc();
?>
<input type="text" required="" name="nombre" placeholder="Nombre..."
value="<?php echo $row['nombre'];?>"><br><br>
<input type="text" required="" name="apellido"
placeholder="Apellido..." value="<?php echo $row['apellido'];?>">
<br><br>
<input type="text" required="" name="correo"
placeholder="Correo..." value="<?php echo $row['correo'];?>"><br>
<br>
<input type="submit" value="Aceptar">
</form>
</center>
</body>
</html>
the error is that when I press modify in the query I get like this:
http://localhost/modificar.php?id=%3C?echo%20$row[%27id%27];?%3E
and the way it should go (for example) is like this:
http://localhost/modificar.php?id=1
Try this:
<?php
include("conexiones.php");
$query="SELECT * FROM usuarios";
$resultado=$conexion->query($query);
?>
<?php while ($row=$resultado->fetch_assoc()): ?>
<tr>
<td><?= $row['id'] ?></td>
<td><?= $row['nombre'] ?></td>
<td><?= $row['apellido'] ?></td>
<td><?= $row['correo'] ?></td>
<td><a href="modificar.php?id=<?= $row['id'] ?>">
Modificar</a></td>
<td><a href="eliminar.php?id=<?= $row['id'] ?>">
Eliminar</a></td>
</tr>
<?php endwhile; ?>
hope it helps.
Related
The first row of this table is shown correctly and centered, while the other rows look like they are just being echo'd out instead of looking like they are part of the table.
This is the part of my code:
<table style="width:20%">
<tr>
<th>ID</th>
<th>Nume</th>
<th>Prenume</th>
</tr>
//fetching data from database
<tr>
<td><?php echo $data['id'];?></td>
<td><?php echo $data['nume'];?></td>
<td><?php echo $data['prenume'];?></td>
</tr>
</table>
The code is supposed to add the written user to a database and display all of the users in a table next to it.
Any help is appreciated! Thanks!
(whole code listed below)
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<form action="index.php" method="post">
<input type="text" name="nume" placeholder="nume" required>
<input type="text" name="prenume" placeholder="prenume" required>
<input type="submit" name="sub" value="Adauga in baza de date">
<br>
</form>
<table style="width:20%">
<tr>
<th>ID</th>
<th>Nume</th>
<th>Prenume</th>
</tr>
<?php
if(isset($_POST['sub']))
{
$pdo = new PDO("mysql:host=localhost;dbname=liamed", "root", "");
$nume = $_POST['nume'];
$prenume = $_POST['prenume'];
$q = "insert into users(nume,prenume)values(:nume,:prenume)";
$r = $pdo->prepare($q);
$r->execute(array(":nume"=>$nume, ":prenume"=>$prenume));
}
$pdo = new PDO("mysql:host=localhost;dbname=liamed", "root", "");
$query = "select * from liamed.users";
$d = $pdo->query($query);
foreach ($d as $data){
?>
<tr>
<td><?php echo $data['id'];?></td>
<td><?php echo $data['nume'];?></td>
<td><?php echo $data['prenume'];?></td>
</tr>
</table>
</body>
<?php }
?>
</html>
You have the end of the table HTML included inside your loop hense the mess. Move that outside the loop and you should be sorted :)
foreach ($d as $data) :
?>
<tr>
<td><?php echo $data['id'];?></td>
<td><?php echo $data['nume'];?></td>
<td><?php echo $data['prenume'];?></td>
</tr>
<?php
endforeach;
?>
</table>
</body>
I am having two php files, one contains a form and another to display the content entered and save button. After confirming the details are correct he has to save and the data should be inserted into the table. I have given the code below
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js">
</script>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.1.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"> </script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"> </script>
</head>
<body>
<?php
$roll=$_POST['roll'];
$sname=$_POST['sname'];
$fname=$_POST['fname'];
$gender=$_POST['gender'];
$aadhar=$_POST['aadhar'];
$caste=$_POST['caste'];
?>
<div class="container container-center">
<!-------------total panel------------------------------------>
<div class="panel-info">
<!------panel heading------>
<div class="panel-heading">
<h2><center><u>STUDENT DETAILS</u></center></h2>
</div> <!-panel heading->
<div class="panel-body">
<form method="post" action="">
<table align="center" border="0">
<tbody>
<tr>
<td rowspan="7"><?php echo"<img src=/photo/$roll.jpg width='200px' height='300px' id='photo'>"; ?></td>
<td>1. Roll Number & Photo:</td>
<td><?php echo"".strtoupper($roll).""; ?></td>
</tr>
<tr>
<td>2. Name of the Student:</td>
<td><?php echo"".strtoupper($sname).""; ?></td>
</tr>
<tr>
<td>3. Name of the Father:</td>
<td><?php echo"".strtoupper($fname).""; ?></td>
</tr>
<tr>
<td>4. Gender:</td>
<td><?php
if($gender=='M')
{ echo"Male";}
else
{echo"Female";}
?></td>
</tr>
<tr>
<td>5. Aadhar Number:</td>
<td><?php echo"$aadhar"; ?></td>
</tr>
<tr>
<td>6. Caste:</td>
<td><?php echo"$caste"; ?></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" id="submit" name="submit" class="btn btn-info" value="save"></td>
</tr>
</tbody>
</table>
</form>
</div>
</div>
</div>
<?php
if(isset($_POST['submit']))
{
echo"<script>alert('success')</script>";
}
?>
</body>
when i click the save button then only the data must be saved. but even if not click the save the php code in isset is executing.
the data obtained by $_POST is from the form.
Please help me.
NOTE:
Actually Problem is that, you don't get the data on this page.. in your POST request with given variable so that Please Just Check it . Other Code Is Fine. !! ( Here I am Just Pass Dummy Data ) Like Below.
$roll= '1234';
$sname='XYZ';
$fname= 'ABC';
$gender= 'M';
$aadhar= '123456789100';
$caste= 'A12345';
Solution: You Have To Get DATA Here in post request from your first_php_page form where user enter the details regarding given fields: roll,sname,fname,gender,aadhar,caste
After here in secound_php_page check that Submit button is set then store the values in varable Like below Code:
NOTE: At The End YoU Have To Write The Insert Query On Save Button Click. To Store The data in Database.
<?php
if(isset($_POST['Submit'])){
$roll=$_POST['roll'];
$sname=$_POST['sname'];
$fname=$_POST['fname'];
$gender=$_POST['gender'];
$aadhar=$_POST['aadhar'];
$caste=$_POST['caste'];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js">
</script>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.1.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"> </script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"> </script>
</head>
<body>
<?php
/*
$roll=$_POST['roll'];
$sname=$_POST['sname'];
$fname=$_POST['fname'];
$gender=$_POST['gender'];
$aadhar=$_POST['aadhar'];
$caste=$_POST['caste'];
*/
// SET THE DUMMY DATA FOR Result check
$roll= '1234';
$sname='XYZ';
$fname= 'ABC';
$gender= 'M';
$aadhar= '123456789100';
$caste= 'A12345';
?>
<div class="container container-center">
<!-- total panel -->
<div class="panel-info">
<!-- panel heading -->
<div class="panel-heading">
<h2><center><u>STUDENT DETAILS</u></center></h2>
</div>
<!--panel heading -->
<div class="panel-body">
<form method="post" action="">
<table align="center" border="0">
<tbody>
<tr>
<td rowspan="7"><?php echo"<img src=/photo/$roll.jpg width='200px' height='300px' id='photo'>"; ?></td>
<td>1. Roll Number & Photo:</td>
<td><?php echo"".strtoupper($roll).""; ?></td>
</tr>
<tr>
<td>2. Name of the Student:</td>
<td><?php echo"".strtoupper($sname).""; ?></td>
</tr>
<tr>
<td>3. Name of the Father:</td>
<td><?php echo"".strtoupper($fname).""; ?></td>
</tr>
<tr>
<td>4. Gender:</td>
<td><?php
if($gender=='M')
{ echo"Male";}
else
{echo"Female";}
?></td>
</tr>
<tr>
<td>5. Aadhar Number:</td>
<td><?php echo"$aadhar"; ?></td>
</tr>
<tr>
<td>6. Caste:</td>
<td><?php echo"$caste"; ?></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" id="submit" name="submit" class="btn btn-info" value="save"></td>
</tr>
</tbody>
</table>
</form>
</div>
</div>
</div>
<?php
if(isset($_POST['submit']))
{
echo"<script>alert('success')</script>";
}
?>
</body>
</HTML>
OUTPUT: DATA Display
AND ONCLICK SAVE
There are few issues with your code, such as:
There's no point having a form and save button(in another page) if you don't have input elements and don't send your data using $_POST superglobal. Create input elements for each of your fields with type="hidden", for example like this:
<td><?php echo strtoupper($roll); ?><input type="hidden" name="roll" value="<?php echo strtoupper($roll); ?>"></td>
Here's the full form code,
// your code
<form method="post" action="">
<table align="center" border="0">
<tbody>
<tr>
<td rowspan="7"><?php echo"<img src=/photo/$roll.jpg width='200px' height='300px' id='photo'>"; ?></td>
<td>1. Roll Number & Photo:</td>
<td><?php echo strtoupper($roll); ?><input type="hidden" name="roll" value="<?php echo strtoupper($roll); ?>"></td>
</tr>
<tr>
<td>2. Name of the Student:</td>
<td><?php echo strtoupper($sname); ?><input type="hidden" name="sname" value="<?php echo strtoupper($sname); ?>"></td>
</tr>
<tr>
<td>3. Name of the Father:</td>
<td><?php echo strtoupper($fname); ?><input type="hidden" name="fname" value="<?php echo strtoupper($fname); ?>"></td>
</tr>
<tr>
<td>4. Gender:</td>
<td>
<?php
if($gender=='M'){
echo"Male";
}else{
echo"Female";
}
?>
<input type="hidden" name="gender" value="<?php echo $gender; ?>">
</td>
</tr>
<tr>
<td>5. Aadhar Number:</td>
<td><?php echo $aadhar; ?><input type="hidden" name="aadhar" value="<?php echo $aadhar; ?>"></td>
</tr>
<tr>
<td>6. Caste:</td>
<td><?php echo $caste; ?><input type="hidden" name="caste" value="<?php echo $caste; ?>"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" id="submit" name="submit" class="btn btn-info" value="save"></td>
</tr>
</tbody>
</table>
</form>
// your code
I don't see any code where you're inserting the form data into the table, you should have a code block like this in another page(where you have displayed the form data and has the save button):
if(isset($_POST['submit'])){
$roll = $_POST['roll'];
$sname = $_POST['sname'];
$fname = $_POST['fname'];
$gender = $_POST['gender'];
$aadhar = $_POST['aadhar'];
$caste = $_POST['caste'];
// your INSERT operation
}
Is this the right way to update a specific column for one row in mysqli_array_fetch? It doesn't work for me.
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>الرد على التذكرة</title>
<style>
.table, tr, td {border: 1px solid black; text-align:center}
.contents { position:static}
p1 {font-size:15px; font-weight:bolder}
.inputresponse {resize:none}
</style>
</head>
<body class="body">
<div class="contents" align="right">
<?php
include 'config.php';
$sql = "SELECT * FROM contact ORDER BY id";
$con->set_charset('utf8');
$users = mysqli_query($con,$sql);
?>
<table class="table">
<?php
while($row = mysqli_fetch_array($users)) {
?>
<form id="<?php echo $row[id] ?>" method="post" name="respone" action="addresponse.php">
<tr>
<td> <p1> الإسم </p1> </td>
<tr>
<td> <?php echo $row[name] ?> </td>
</tr>
<tr>
<td> <p1> رقم التذكرة</p1> </td>
</tr>
<tr>
<td> <?php echo $row[ticketnumber] ?> </td>
</tr>
<tr>
<td> <p1> الإيميل</p1> </td>
</tr>
<tr>
<td> <?php echo $row[email] ?> </td>
</tr>
<tr>
<td> <p1> الموضوع </p1> </td>
</tr>
<tr>
<td> <?php echo $row[subject] ?> </td>
</tr>
<tr>
<td> <p1> الرد </p1> </td>
</tr>
<tr>
<td> <textarea name="response" rows="5" dir="rtl" class="inputresponse"> </textarea> </td>
</tr>
<tr>
<td> <input type="submit" value="إرسال" name="send"> </td>
</tr>
<tr>
<td>
<?php
if(isset($_POST['send'])){
$repsonse = $_POST['response'];
$result = ("UPDATE contact SET response ='$response' WHERE id= $row[id]");
$rst = mysqli_query($con,$result);
if($rst){
echo "تم الإرسال";
} else {
echo " لم يتم الإرسال";
}
}
}
?>
</form>
</table>
</div>
</body>
</html>
after editing, I think I did it in wrong again
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>الرد على التذكرة</title>
<style>
.table, tr, td {border: 1px solid black; text-align:center}
.contents { position:static}
p1 {font-size:15px; font-weight:bolder}
.inputresponse {resize:none}
.inputid {text-align:center; font-size:10px}
</style>
</head>
<body class="body">
<div class="contents" align="right">
<?php
include 'config.php';
$sql = "SELECT * FROM contact ORDER BY id";
$con->set_charset('utf8');
$users = mysqli_query($con,$sql);
?>
<table class="table">
<?php
while($row = mysqli_fetch_array($users)) {
?>
<form id="<?php echo $row['id'] ?>" method="post" name="respone" action="addresponse.php">
<tr>
<td> <input value="<?php echo $row['id'] ?>" name="id" class="inputid" readonly> </td>
<tr>
<tr>
<td> <p1> الإسم </p1> </td>
<tr>
<td> <?php echo $row['name'] ?> </td>
</tr>
<tr>
<td> <p1> رقم التذكرة</p1> </td>
</tr>
<tr>
<td> <?php echo $row['ticketnumber'] ?> </td>
</tr>
<tr>
<td> <p1> الإيميل</p1> </td>
</tr>
<tr>
<td> <?php echo $row['email'] ?> </td>
</tr>
<tr>
<td> <p1> الموضوع </p1> </td>
</tr>
<tr>
<td> <?php echo $row['subject'] ?> </td>
</tr>
<tr>
<td> <p1> الرد </p1> </td>
</tr>
<tr>
<td> <textarea name="response" rows="5" dir="rtl" class="inputresponse"> </textarea> </td>
</tr>
<tr>
<td> <input type="submit" value="إرسال" name="send"> </td>
</tr>
<tr>
<td>
<?php
if(isset($_POST['send'])){
$response = $_POST['response'];
$result = ("UPDATE contact SET response ='$response' WHERE id= $row[id]");
$rst = mysqli_query($con,$result);
if($rst){
echo "تم الإرسال";
} else {
echo " لم يتم الإرسال";
}
}
}
?>
</form>
</table>
</div>
</body>
</html>
Your HTML formatting is strange but I think this should accomplish what you want.
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>الرد على التذكرة</title>
<style>
.table, tr, td {
border: 1px solid black;
text-align:center
}
.contents {
position:static
}
p1 {
font-size:15px;
font-weight:bolder
}
.inputresponse {
resize:none
}
.inputid {
text-align:center;
font-size:10px
}
</style>
</head>
<body class="body">
<div class="contents" align="right">
<?php
include 'config.php';
$sql = "SELECT * FROM contact ORDER BY id";
$con->set_charset('utf8');
$users = mysqli_query($con,$sql);
?>
<table class="table">
<?php
while($row = mysqli_fetch_array($users)) {
?>
<form id="<?php echo $row['id'] ?>" method="post" name="respone" action="addresponse.php">
<tr>
<td><input value="<?php echo $row['id'] ?>" name="id" class="inputid" type="hidden"></td>
<tr>
<tr>
<td><p1> الإسم </p1></td>
<tr>
<td><?php echo $row['name'] ?></td>
</tr>
<tr>
<td><p1> رقم التذكرة</p1></td>
</tr>
<tr>
<td><?php echo $row['ticketnumber'] ?></td>
</tr>
<tr>
<td><p1> الإيميل</p1></td>
</tr>
<tr>
<td><?php echo $row['email'] ?></td>
</tr>
<tr>
<td><p1> الموضوع </p1></td>
</tr>
<tr>
<td><?php echo $row['subject'] ?></td>
</tr>
<tr>
<td><p1> الرد </p1></td>
</tr>
<tr>
<td><textarea name="response" rows="5" dir="rtl" class="inputresponse"> </textarea></td>
</tr>
<tr>
<td><input type="submit" value="إرسال" name="send"></td>
</tr>
</form>
<?php
}
?>
</table>
<?php
if(isset($_POST['send'])){
$response = $_POST['response'];
$result = "UPDATE contact SET response = ? WHERE id= ?";
$rst = mysqli_prepare($con,$result);
mysqli_stmt_bind_param($rst, 'si', $response, $_POST['id']);
mysqli_stmt_execute($rst);
if($rst){
echo "تم الإرسال";
} else {
echo " لم يتم الإرسال";
echo mysqli_stmt_error($rst);
}
}
?>
</div>
</body>
</html>
Changes/potential improvements:
Using prepared statements in place of inline values.
Moved update outside of while loop since it is irrelevant.
Moved closing form tag inside the while loop. As is you were making multiple forms but every one was a child of the first because it never closed.
The p1s look like they might be headings? If so they should be outside of the loop.
If you want to display a message next to the row that was updated you could move the whole update process before the page process. Assign it to a variable the status to a variable then in the outputting when you are on that record output the message as well.
Your table rows seem to be closing incorrectly.
I just made a PHP script to retrieve entry from database. When I retrieve entry from a table, the page look like this. The header and form below table is repeated. I need help, thanks.
Here's the whole code I'm using:
<?php
session_start();
include('connection.php');
$username='username';
mysql_query("SELECT * FROM regmember WHERE username='$username'");
$query=("SELECT * FROM product");
$result=mysql_query($query);
while($row=mysql_fetch_array($result))
{
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="index.css">
<title>Music Light</title>
<div align="center"><h1>Music Light</h1></div>
<div id="menu">
<ul>
<li><?php echo 'Welcome, '.$_SESSION['username']; ?></li>
<li>Home</li>
<li>Product</li>
<li>Profile</li>
<li>Cart</li>
<li>Testimony</li>
<li>Transaction</li>
<li>Logout</li>
</ul>
</div>
<br>
<br>
<div align="center">
<table border="0">
<tr>
<td>ID</td>
<td></td>
<td><?php echo $row[0];?></td>
</tr>
<tr>
<td>Brand</td>
<td></td>
<td><?php echo $row[1];?></td>
</tr>
<tr>
<td>Instrument Type</td>
<td></td>
<td><?php echo $row[2];?></td>
</tr>
<tr>
<td>Price</td>
<td></td>
<td><?php echo $row[3];?></td>
</tr>
<tr>
<td>Stock</td>
<td></td>
<td><?php echo $row[4];?></td>
</tr>
<tr>
<td>Image</td>
<td></td>
<td><img height="150" width="150" src="productimg/<?php echo $row[6];?>"/></td>
</table>
</div>
<div align="center">
<table>
<form name="deleteentry" action="delete.php" method="get">
<tr>
<td>Delete which entry? (enter product id)</td>
<td><input type="text" name="delete"></td>
<td><input type="button" name="deletebutton" value="Delete"></td>
</tr>
</form>
</table>
</div>
<?php
}
?>
<br>
<br>
<div align="center"><p>Description template</p></div>
<footer>
<p align="center">Copyright © 2013 Music Light</p>
</footer>
missing </head> and <body> and </body>
i would suggest that the <html> <head></head> and <body> to be used outside the loop if u donot actually want to repeat. by loop i mean the while loop
You didn't closed your header with </head>
<head>
<link rel="stylesheet" type="text/css" href="index.css">
<title>Music Light</title>
</head> <= Include this
.
.
.
</html> <= Include this as well at the end
I have a couple of problems. I'm creating a form inside a table, from what I understand this is not a good idea. But because of the loop I want to make sure the table header is outside so it doesn't repeat. Is there a smarter way to do this?
Also more importantly I can't seem to get the delete button to remove the correct video. It seems to delete the last one in the list. Something wrong with how I'm looping over this?
<p>
<h3>Recorded Videos</h3>
<table id="webcam-table">
<thead>
<tr>
<td>Camera Name</td>
<td>Video Size</td>
<td>Date Created</td>
<td>Video Length</td>
<td>Video Options</td>
</tr>
</thead>
for($i=0;$i<$num_videos;$i++)
{
<form action="<?php htmlentities($_SERVER['PHP_SELF']);?>" method="POST">
<input type="hidden" name="video_id" value="<?php echo $result_videos[$i]["video_id"]; ?>" />
<tbody>
<tr>
<td>
<?php echo $result_videos[$i]["camera_name"]; ?>
</td>
<td>
<?php echo $result_videos[$i]["video_size"]; ?>
</td>
<td>
<?php echo $result_videos[$i]["video_datetime"]; ?>
</td>
<td>
<?php echo $result_videos[$i]["video_length"]; ?>
</td>
<td>
<input type="submit" name="delete_video" value="Delete" onClick="javascript:return confirm('Delete this video?');"/>
</td>
</tr>
</tbody>
}
echo "</table>";
echo "</form>";
echo "</p>";
}
}
if (isset($_POST['delete_video'])) {
$video_id = $_POST['video_id'];
$query_delete_video = 'DELETE FROM `#__videos` WHERE `video_id`='.$video_id;
$db->setQuery($query_delete_video);
$db->query();
header("location: " . $_SERVER['REQUEST_URI']);
In your loop you are creating the 'form' tag. However you are not closing it each time. This is causing your deleting problem.
Move
echo "</form>";
Inside the loop.
looks good to me, the only issue I see is that the tag should be outside the loop (opening before, closing after).
Revised code
<?
if (isset($_POST['delete_video']))
{
$video_id = $_POST['video_id'];
$query_delete_video = 'DELETE FROM `#__videos` WHERE `video_id`='.$video_id;
$db->setQuery($query_delete_video);
$db->query();
header("location: " . $_SERVER['REQUEST_URI']); //you should not allow things to be echoed before a header()
}
?>
<script type="text/javascript">
function onMySubmit(video_id)
{
document.myform.video_id.value = video_id;
return confirm('Delete this video?');
}
</script>
<p>
<h3>Recorded Videos</h3>
<!-- you had <?php htmlentities(...) ?>, you should have had
<?php echo htmlentities(...) ?> or <?= ... ?> -->
<form name="myform" action="<?= htmlentities($_SERVER['PHP_SELF']);?>" method="POST">
<input type="hidden" name="video_id" value="" />
<table id="webcam-table">
<thead>
<tr>
<td>Camera Name</td>
<td>Video Size</td>
<td>Date Created</td>
<td>Video Length</td>
<td>Video Options</td>
</tr>
</thead>
<tbody>
<? for($i=0;$i < $num_videos;$i++) { ?>
<tr>
<td><?= $result_videos[$i]["camera_name"]; ?></td>
<td><?= $result_videos[$i]["video_size"]; ?></td>
<td><?= $result_videos[$i]["video_datetime"]; ?></td>
<td><?= $result_videos[$i]["video_length"]; ?></td>
<td><input type="submit" name="delete_video" value="Delete" onClick="javascript:return onMySubmit(<?=$result_videos[$i]["video_id"];?>);"/></td>
</tr>
<? } ?>
</tbody>
</table>
</form>
</p>