I am trying to update whatever content in the textbox that has been edited and post to database. However, only the second record is update but the first record is not. I think should be the while loop problem but I don't what is the mistake.
Here's my edit page code:
viewadmindb.php
<?php
session_start();
include('adminconfig.php');
$sql = "SELECT * FROM admin ORDER BY ID";
$result = mysql_query($sql);
?>
<body>
<div id="wrap">
<div id="status"></div>
<form method="POST" action="adminsave.php" onSubmit="return validate(this);">
<table class="viewdb" contentEditable="true">
<tr><td id='fcolor' style='border:2px solid black' align=center> ID </td>
<td id='fcolor' style='border:2px solid black' align=center> Name </td>
<td id='fcolor' style='border:2px solid black' align=center> Password </td>
<td id='fcolor' style='border:2px solid black; width:auto;' align=center>
Department</td>
<td id='fcolor' style='border:2px solid black' align=center> Email </td></tr>
<div id="content">
<?php
while($row = mysql_fetch_array($result)){ ?>
<tr>
<td style='border:2px solid black; width:auto' align=center><?php echo $row[] =
$row['ID'] ?></td>
<td style='border:2px solid black' align=center> <?php echo $row[]
= $row['name'] ?> </td>
<td style='border:2px solid black' align=center> <?php echo $row[] =
$row['password'] ?> </td>
<td style='border:2px solid black; width:200px' align=center> <?php echo $row[] =
$row['department'] ?> </td>
<td style='border:2px solid black' align=center> <?php echo $row[] = $row['email']
?> </td>
<tr>
<td><input id='edit' type = 'text' name="ID[]" value='<?php echo $row['ID'] ?>'
maxlength="50"></td>
<td><input id='edit' type = 'text' name="name[]" value='<?php echo $row['name']
?>'
maxlength="50"></td>
<td><input id='edit' type = 'text' name="password[]" value='<?php echo
$row['password'] ?>' maxlength=50"></td>
<td><input id='edit' type = 'text' name="department[]" value='<?php echo
$row['department'] ?>' maxlength="50"></td>
<td><input id='edit' type = 'text' name="email[]" value='<?php echo
$row['email']?>'
style='width:300px' " maxlength="50"></td>
<?php } ?>
<td><input id='edit' type='submit' name='<?php $row['ID'] ?>' value='Submit'/>
</td></tr>
</table>
</form>
<?php
$ID=$row['ID'];
$name=$row['name'];
$password=$row['password'];
$department=$row['department'];
$email=$row['email'];
?>
adminsave.php
<?php
session_start();
include('adminconfig.php');
$ids=$_POST['ID'];
$name_arr=$_POST['name'];
$password_arr=$_POST['password'];
$department_arr=$_POST['department'];
$email_arr=$_POST['email'];
foreach(($ids as $key=>$id) {
$name = $name_arr[$key];
$password = $password_arr[$key];
$department = $department_arr[$key];
$email = $email_arr[$key];
$sql = "UPDATE admin SET name = '$name',password = '$password',
department ='$department',email = '$email' WHERE ID = '$id'";
}
$result = mysql_query($sql);
if(!$result){
die('invalid query:'.mysql_error());
}
else
echo ("<tr><td>" . "Data updated succesfully..." . "</td></tr>");
header('Refresh:5; url=viewadmindb.php');
die;
?>
You really should look up into how ID's are supposed to work in html. The basic things is that ID must be unique. You should not have two or more elements with same ID. But in your case it's the name-attribute that is the issue.
If you have a loop like this...
while($row = mysql_fetch_array($result)){ ?>
<tr>
<td><input id='edit' type = 'text' name="ID" value='<?php echo $row['ID'] ?>'
maxlength="50"></td>
</tr>
}?>
...and you have two rows from the $result-recordset, you will echo out html something like this:
<tr>
<td><input id='edit' type = 'text' name="ID" value='1'
maxlength="50"></td>
</tr>
<tr>
<td><input id='edit' type = 'text' name="ID" value='2'
maxlength="50"></td>
</tr>
Your then saving values into the database based on a element with name ID. But the problem is that PHP doesn't know which of the rows above it should use (How could PHP know?). When refering to an element that has a duplicate the last element in the DOM is used. Therefore only this row is take into account:
<tr>
<td><input id='edit' type = 'text' name="ID" value='2'
maxlength="50"></td>
</tr>
There are no loop in adminsave.php that indicates you want to save several values. It just tells that you want to save content into database with a specific ID.
$sql = "UPDATE admin SET name = '$name',password = '$password',
department ='$department',email = '$email' WHERE ID = '$ID'";
and because the last row in the DOM is used, the update-statement would be:
$sql = "UPDATE admin SET name = '$name',password = '$password',
department ='$department',email = '$email' WHERE ID = '2'";
You can solve this by making the name-element an array by adding brackets to name-elements: (Also make edit a class instead of an id because it's ok to have duplicate classes but not duplicate ids)
<tr>
<td><input class='edit' type = 'text' name="ID[]" value='<?php echo $row['ID'] ?>'
maxlength="50"></td>
</tr>
But then you would also have to loop through the array
<?php
$ids = $_POST['ID']; //Get array from form
$name_arr = $_POST['name'];
$password_arr = $_POST['password'];
$department_arr = $_POST['department'];
$email_arr = $_POST['email'];
foreach($ids as $key=>$id) {
//Get specific element in each array
$name = $name_arr[$key];
$password = $password_arr[$key];
$department = $department_arr[$key];
$email = $email_arr[$key];
//Create sql and execute
$sql = "UPDATE admin SET name = '$name',password = '$password',
department ='$department',email = '$email' WHERE ID = '$id'";
$result = mysql_query($sql);
}
The row:
$sql = "SELECT * FROM admin WHERE $ID = '$ID'";
is pointless because the variable $sql is overritten on the next row.
Note that above is just for demonstrating how the basic concepts of ids, names and arrays works when handling forms. You should really not just mysql_* functions, but instead read up on PDO or mysqli instead. You should sanitize (make sure unwanted data is not injected into db) before updating.
The whole Logic is wrong.
Just pass in the query string from main page to another php page ex from:admin_detail.php to edit_admin.php
Then query db for data based on passed query string
echo them in desired textbox.
then call update statement.
viewadmindb.php
The var $row you didnot set. Just ad this $row = mysql_fetch_array($reslult); before you access to table values.
What is this $row[] = $row['name'] ? You refill $row, and after you cannot access the original value from database. Use ony labels, no vars like <td> E-mail: </td>
adminsave.php
You rewrited the $sql var. The line $sql = "SELECT * FROM admin WHERE $ID = '$ID'; you donot need to use.
Good tip: use the css syntax ` and border the varchars with {$var}:
"UPDATE `admin` SET `name` = '{$name}', `password` = '{$password}', `department` = '{$department}', `email` = '{$email}' WHERE `ID` = '{$ID}'"
It seems you are new to php.
Your code is not well formated and not really readable.
Don't do $_POST['...'] and write this value directly into database (security issue => mysql injection) So please insert mysql_real_escape_string($value) before you insert into database.
What the hack is that? echo $row[] = $row['password'] don't do that! only echo is enough.
Solution of your answer:
It's normal that your code update only the last iteration of the while loop, because only the last value will be stored into the $_POST array.
If you wanna fix that you have to make the form as array like:
<input id='edit' type = 'text' name="name[]" value='<?php echo $row['name'] ?>'
maxlength="50">
Then in your viewadmindb.php you have to iterate over this values again and make for each value an extra update query which updates the value in the database.
UPDATE:
The foreach loop should look like this in adminsave.php:
$arrIds = array();
$arrNames = array();
$arrDepartments = array();
$arrPasswords = array();
// ... add all necessary vars you wan a fetch from the post request
$arrIds[] = $_POST['name'][];
$arrNames[] = $_POST['name'][];
$arrDepartments[] = $_POST['department'][];
$arrResults = array(); // To store result data if necessary
foreach($arrIds as $key => $item) {
// Build sql query
$sql = "UPDATE admin SET name = '". $arrNames[$key] . "',password = '". $arrPasswords[$key] . "',
department ='". $arrDepartments[$key] . "',email = '". $arrEmailss[$key] . "' WHERE ID = '$item'";
// Execute query!
$arrResults[] = mysql_query($sql);
}
So now you should be able to get it running...
Related
I would like to move to the next record using an HTML button. I have tried for and foreach SQL statements I have also tried using num rows and calling the cells values.
$id=$_get['Badge ID Number'];
$sqlkc = "select * from Badges.BADGEMSTR";
$result = mysqli_query($sqlc, $sqlkc);
if($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
{
$BIDN= $row['Badge ID Number'];
$Fname= $row['First Name'];
$MI= $row['Middle Initial'];
$Lname= $row['Last Name'];
}
$next = next($result);
?>
Thank you in advance for your help.
Forgot to add my current onclick command
onclick='<?php echo $next;?>'
All HTML code as requested
<table style="background-color: tan; margin: auto">
<tr>
<td><input type="text" value="<?php echo $BIDN;?>"/>
<input type="text" value="01"/></td>
</tr>
<tr>
<td>
<input type="text" value="<?php echo $Fname;?>"/>
<input type="text" value="<?php echo $MI;?>"/>
<input type="text" value="<?php echo $Lname;?>"/>
</td>
</tr>
<tr>
<td><input type="button" value="Next" style="float: right" onclick='<?php echo $next;?>'/></td>
<td><input type="button" value="Last" style="float: right" onclick='<?php echo $nextid;?>'/></td>
</tr>
</table>
I hope I understood the question right.
Since you would pass the Badge ID between pages, you should use prepared statements as such. So, taking the Badge ID Number is Integer, your PHP code should look like this:
$link = mysqli_connect(hostname,username,password,dbname);
if (isset($_GET['last_id'])) {
// Last row in the table
$stmt = mysqli_prepare($link, 'SELECT * FROM Badges.BADGEMSTR ORDER BY `Badge ID Number` DESC LIMIT 1');
} elseif (isset($_GET['id'])) {
// Specific row in the table
$stmt = mysqli_prepare($link, 'SELECT * FROM Badges.BADGEMSTR WHERE `Badge ID Number`>? ORDER BY Rb ASC LIMIT 1');
$stmt->bind_param('d',$_GET['id']);
} else {
// First row in the table
$stmt = mysqli_prepare($link, 'SELECT * FROM Badges.BADGEMSTR ORDER BY `Badge ID Number` ASC LIMIT 1');
}
// Execute the query and get the results
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_array();
// Initialize variables from the given $row
$BIDN = $row['Badge ID Number'];
$Fname = $row['First Name'];
$MI = $row['Middle Initial'];
$Lname = $row['Last Name'];
As for the HTML code, it's a bit unclear from the question, but I think something like this would be in order:
<html>
<head></head>
<body>
<table style="background-color: tan; margin: auto">
<tr>
<td><?php echo htmlspecialchars($BIDN, ENT_QUOTES); ?></td>
<td>01</td>
</tr>
<tr>
<td><?php echo htmlspecialchars($Fname, ENT_QUOTES); ?></td>
<td><?php echo htmlspecialchars($MI, ENT_QUOTES); ?></td>
<td><?php echo htmlspecialchars($Lname, ENT_QUOTES); ?></td>
</tr>
<tr>
<td>
Next
</td>
<td>
Last
</td>
</tr>
</table>
</body>
</html>
You also don't have to use inputs to display the results, you could show them between TD elements in the table like <td><?php echo $row['Badge ID Number']; ?>.
I'm trying to create a form which allows you to update a database table using php.
I'm kinda new to PHP so excuse me if I make a stupid mistake in the code.
This is my edit.php code:
<html>
<head>
</head>
<body>
<?php
$con=mysqli_connect("localhost","root","root","test");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM cats");
?>
<form method="post" action="<?php $_PHP_SELF ?>">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<?php
while($row = mysqli_fetch_array($result))
{
$name = $row['name'];
$email = $row['email'];
$rank = $row['rank'];
$birth = $row['birth'];
$joined = $row['joined'];
$steamid = $row['steamid'];
?>
<td width="100"></td>
<td><?=$name?></td>
</tr>
<tr>
<td width="100">Email</td>
<td><input name="emailid" type="text" value="<?=$email?>"></td>
</tr>
<tr>
<td width="100">Rank</td>
<td><input name="rankid" type="text" value="<?=$rank?>"></td>
</tr>
<tr>
<td width="100">Birth</td>
<td><input name="birthid" type="text" value="<?=$birth?>"></td>
</tr>
<tr>
<td width="100">Joined</td>
<td><input name="joinedid" type="text" value="<?=$joined?>"></td>
</tr>
<tr>
<td width="100">Steamid</td>
<td><input name="steamidid" type="text" value="<?=$steamid?>"></td>
</tr>
<?php } ?>
<tr>
<td width="100"> </td>
<td> </td>
</tr>
<tr>
<td width="100"> </td>
<td>
<input name="update" type="submit" id="update" value="Update">
</td>
</tr>
</table>
</form>
<?php
if(isset($_POST['update']))
{
$name = $row['nameid'];
$email = $row['emailid'];
$rank = $row['rankid'];
$birth = $row['birthid'];
$joined = $row['joinedid'];
$steamid = $row['steamidid'];
$update = mysqli_query($con,"UPDATE cats SET email = '$email', rank = '$rank', birth = '$birth', joined = '$joined', steamid = '$steamid' WHERE name = '$name';");
$retval = mysqli_query($con,"UPDATE cats SET email = '$email', rank = '$rank', birth = '$birth', joined = '$joined', steamid = '$steamid' WHERE name = '$name';");
if (!$update) {
echo "Could not update data: " . mysqli_error($con);
}
echo "Updated data successfully\n";
}
mysqli_close($con);
?>
</body>
</html>
It shows the table and information but the updating isn't working.
Updated data successfully
I've checked the database but it's not updating anything.
Dear i think you change the record based on Name because you can use $name in where clause and you can also change the Name than never true where clause so that your query execute successfully but not effected on any of the row.
you want to get for editable record and that's unique id base update row it will defiantly work.
Try to use PHP PDO database access functions, your code as it stands is vulnerable to SQL-Injection! PDO will also make debugging and working with the database much easier.
I think your check for "update" in $_POST is not working because update is not a field inside your form but the submit button itself, try to check for one of the fields instead.
Informations:
With mysqli_error() you need to write about which connection you want to get errors, like this:
mysqli_error($con);
With mysqli_query() you need to give two parameters, connection and query like this:
$update = mysqli_query($con,"UPDATE cats SET email = '$email', rank = '$rank', birth = '$birth', joined = '$joined', steamid = '$steamid' WHERE name = '$name';");
How to debug:
If you want to check that UPDATE query return any error you can do something like this:
if (!$update) {
echo "Could not update data: " . mysqli_error($con);
}
You can try to debug your query with something like this:
$sql = "UPDATE cats SET email = '$email', rank = '$rank', birth = '$birth', joined = '$joined', steamid = '$steamid' WHERE name = '$name';";
echo $sql; // this output write in your phpMyadmin to check if there are any errors.
$update = mysqli_query($con, $sql);
Other problem we got:
1. I think also you should have else in your code, f.ex.:
if (!$update) {
echo "Could not update data: " . mysqli_error($con);
} else {
echo "Updated data successfully\n";
}
2. You are not getting data from $_POST it should be like:
$name = $_POST['nameid']; // not $row['nameid']
$email = $_POST['emailid'];
$rank = $_POST['rankid'];
$birth = $_POST['birthid'];
$joined = $_POST['joinedid'];
$steamid = $_POST['steamidid'];
More about used functions:
PHP: mysqli::$error
PHP: mysqli::query
In your case it is Procedural style
Look like everything is working fine with this code but in fact fails to update the database, Data are displayed correctly while fetching data but when i press update Button the data disappear but no update has been executed. It look fine to me but seems i am wrong.
This is a project for my professor so i don't care for the SQL injection and others.
<html>
<head>
<link rel="stylesheet" type="text/css" href="btnstyle.css">
<title>Managament System</title>
</head>
<body>
<h1>TU Chemnitz Student managament system</h1>
<br>
ADD Person
Edit Person
Manage Boards
Manage Departments
Search N&S
Triple Search
Membership
<br>
<br>
<?php
// set database server access variables:
$host = "localhost";
$user = "";
$pass = "";
$db = "";
// open connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
// create query
$querys = "SELECT * FROM tblperson";
// execute query
$result = mysql_query($querys) or die ("Error in query: $query. ".mysql_error());
echo "<table border=1 align=center>
<tr>
<th>Personal ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Deparment</th>
<th>Board</th>
<th>Marticulation Number</th>
<th>Reg Date</th>
<th>Action</th>
</tr>";
while($row = mysql_fetch_array($result)) {
?>
<?php
echo '<tr>';
echo '<td>'. $row['personid'].'</td>';
echo '<td>'. $row['personname'].'</td>';
echo '<td>'. $row['personsurname'].'</td>';
echo '<td>'. $row['persondepartment'].'</td>';
echo '<td>'. $row['personboard'].'</td>';
echo '<td>'. $row['martinumber'].'</td>';
echo '<td>'. $row['personregdate'].'</td>';
echo '<td>'.' EDIT '.'</td>';
}
?>
</body>
</html>
and this is the edit file which seems to problematic.
<?php
include_once('coneksioni.php');
if(isset($_GET['edit']))
{
$personid = $_GET['edit'];
$res = mysql_query("SELECT * FROM tblperson WHERE personid='$personid'");
$row = mysql_fetch_array($res);
}
if(isset($_POST['newpersonname']))
{
$newpersonname = $_POST['newpersonname'];
$personid = $_POST['personid'];
$sql = "UPDATE tblperson SET personname = '$newpersonname' WHERE personid = '$personid'";
$res = mysql_query($sql) or die ("Cant be updated");
echo "< meta http-equiv='refresh' content='0;url=home.php'>";
}
?>
<form action="edit20.php" method="POST">
<table border="0">
<tr>
<td>First Name</td>
<td><input type="text" name="newpersonname" value="<?php echo $row[1];?>" maxlength="30" size="13"></td>
</tr>
<tr>
<td>Last Name</td>
<td> <input type="text" name="personsurname" value="<?php echo $row[2];?>" maxlength="30" size="30"></td>
</tr>
<tr>
<td>Department</td>
<td>
<select name='persondepartment'>
<option>Production</option>
<option>Sales</option>
</select>
</td>
</tr>
<tr>
<td>Board</td>
<td>
<select name='personboard'>
<option>Evaluation</option>
<option>Executive</option>
<option>Research</option>
</select>
</td>
</tr>
<tr>
<td>Marticulation Number</td>
<td> <input type="text" name="martinumber" maxlength="60" size="30"></td>
</tr>
<tr>
<td>Date of Registration</td>
<td><input type="date" name="personregdate" maxlength="7" size="7"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value=" Update"></td>
</tr>
</table>
</form>
You are looking for personid when the Update button is pressed on the form in edit20.php but that value has never been set so it will be empty and the update will fail.
After
<form action="edit20.php" method="POST">
add:
<input type="hidden" name="personid" value="<?php echo $personid; ?>">
On edit page seem your confusing the same variable with different values. If you state $personid variable to contain the edit value from get, then just re-use the variable don't assign new value. On this line you assign new value :
$personid = $_POST['personid'];
Don't assign new value since it has the initial value already to use just set the variable global for usage
$personid = $_GET['edit'];
Or else create a hidden element and pass edit value into it.
Please add name attribute for your update button
<td colspan="2"><input type="submit" name="update" value=" Update"></td>
and chk whether the update button set or reset as in the place of
if(isset($_POST['newpersonname'])) // change text 'newpersonname' as 'update'
You use a variable that doesn't excist:
<?php
include_once('coneksioni.php');
if(isset($_GET['edit']))
{
$personid = $_GET['edit'];
$res = mysql_query("SELECT * FROM tblperson WHERE personid='$personid'");
$row = mysql_fetch_array($res);
}
if(isset($_POST['newpersonname']))
{
$newpersonname = $_POST['newpersonname'];
$personid = $_POST['personid']; // this doesn't excist
$sql = "UPDATE tblperson SET personname = '$newpersonname' WHERE personid = '$personid'";
$res = mysql_query($sql) or die ("Cant be updated");
echo "< meta http-equiv='refresh' content='0;url=home.php'>";
}
?>
$personid = $_POST['personid']; doesn't excist in your code. Its simply a piece of code you put in there to probably proces, but forgot to define the variable in the code. Place the following in your form.
<input type="hidden" name="personid" value="<?php echo $_GET['edit']; ?>">
You only use this just once because you send the form back after proces to your home, hence it wont be used anymore. You can also use the avariable you defined as $personid; on that position.
If that fails, something maybe wrong in your query. Try to echo out the query (remove qucikly the meta command) by simply just do echo $sql after you do the sql query. 9 out of 10 times, it's a typo.
I am trying to update multiple rows on submit of a form (in particular this one is the "hours" field.
I have it working but only one of the value updates vs all of them.
There is the possibility of having different values for each update.
The form code:
$query2 = "select * FROM work_hours WHERE formid = $formid ";
$result = $mysqli->query( $query2 );
$num_results = $result->num_rows;
if( $num_results > 0){
echo " <table border='0' align='center'>
<tr>
<td colspan='2' align='center'>
<strong> Time Away Break Down</strong>
</td>
</tr>
<tr>
<td align='center'>Date</td>
<td align='left'>Hours</td>
</tr>";
while( $row = $result->fetch_assoc() ){
extract($row);
echo " <tr>
<td class='hidden_sm' align='center'>
<input type='text' name='id' size='10' value='$id' class='dept' readonly style='width:30px;'>
<input type='text' name='date' size='40' value='$date' class='dept' readonly> <input type='text' name='end_date' size='40' value='$end_date' class='dept' readonly>
</td>
<td class='hidden_sm' align='left' >
<input type='text' name='hours' size='10' style='width:30px;' value='$hours' class='dept' >
</td>
</tr>
";
}
echo "<tr>
<td colspan='2' align='center'>
<input type='submit' name='Submit' value='Submit Request'>
</td>
</tr>
</form>
</table>";//end table
Submit Code:
$id = $_POST['id'];
$formid = $_POST['formid'];
$hours = $_POST['hours'];
include 'connect-db.php';
$stmt = $mysqli->prepare("UPDATE work_hours SET hours = ? WHERE formid = ?");
$stmt->bind_param('si',
$_POST['hours'],
$_POST['formid']);
$stmt->execute();
if ( $stmt ) {
echo "<p align='center'>Thank you, this request has been approved.<BR>You will be redirected in 5 seconds</p>";
} else {
echo "Error, you status cannot be updated. <BR> Please contact your system administrator.";
}
$stmt->close();
?>
Could anyone point me in the right direction to have all values update on submit, as I have had zero luck.
As well I do understand the need to prevent SQL Injections, and that I am working, so no need to remind me.
Thanks in advance!
Looks like you'll want to use a CASE statement as explained here:
How does MySQL CASE work?
Use a loop to build the statement and you're better off using the id as the identifier instead of formid, since the id is the unique value and you could have different results in the form.
Im loading content for my website from database. It loads data and fills a table.
My problem is that i have put a button next to each row. When i click on the button it has to show me the Name, Price ,Stock etc of every row.
When i click on the button i get an error.
Here you can find the code i have written in de document User_Koeken.php
<?php
if (isset($_POST[$ID]))
{
$URL = $_POST['S_URL'];
$Naam = $_POST['S_Naam'];
$Inhoud = $_POST['S_Inhoud'];
$Stock = $_POST['S_Stock'];
$Prijs = $_POST['S_Prijs'];
echo $URL."".$Naam."".$Inhoud."".$Stock."".$Prijs;
}
else
{$supermarket = mysql_connect("localhost", "root", "Password") or die(mysql_error());
mysql_select_db("supermarket", $supermarket);
$sql = " select * from koeken";
$result = mysql_query($sql, $supermarket);
while ($row = mysql_fetch_array($result)) {
$ID = $row['ID'];
$URL = $row['URL'];
$Naam = $row['Naam'];
$Inhoud = $row['Inhoud'];
$Stock = $row['Stock'];
$Prijs = $row['Prijs'];
$_SESSION['ID']=$ID;
echo "<form action='User_Koeken.php' method='post'>
<tr class='rien' >
<td name='S_URL'><a href=$URL><img src=$URL alt='product'></a></td>
<td name='S_Naam'>$Naam</td>
<td Name='S_Inhoud'>$Inhoud</td>
<td name='S_Stock'>$Stock</td>
<td name='S_Prijs'>€ $Prijs</td>
<td><input type='submit' value=$ID name='$ID'></td>
</tr>
</form> ";
}; }?>
Here you can find a picture of my code in color
http://postimg.org/image/n6wrb0d13/
http://postimg.org/image/n6wrb0d13/
$ID must be initialized before the line
if (isset($_POST[$ID]))
Otherwise, this will always return false, or an error.
Instead, use an array in your HTML names to catch the row being posted:
<tr class='rien' >
<td name='myform[S_URL]'><a href='$URL'><img src='$URL' alt='product'></a></td>
<td name='myform[S_Naam]'>$Naam</td>
<td Name='myform[S_Inhoud]'>$Inhoud</td>
<td name='myform[S_Stock]'>$Stock</td>
<td name='myform[S_Prijs]'>€ $Prijs</td>
<td><input type='submit' value='$ID' name='myform[id]'></td>
</tr>
and the PHP:
if (isset($_POST['myform']) ) {
$post = $_POST['myform'];
$ID = $post['id'];
$URL = $post['S_URL'];
....
}