Dynamic Form to Database - php

I'm trying to make a log of cars going in and out of a parking lot.
The car info is retrieved from a database and is working fine. The problem I'm having is getting the in/out times to store into the database. In a previous page I had done it so that the form was separate from the table and the input info would be updated but for this page I need to have a dynamic amount of fields varying on the cars in the database. I am not sure what I am doing wrong but here is my code, the data is not being sent or stored in the data base.
<h3>Update Car</h3>
<form action="carLog.php" method="post">
<fieldset>
<legend>Car Log</legend>
<?php //This prints out the car log data
$sql = "SELECT * FROM carLog";
$result = $databaseConnection->query($sql);
echo "<table class='TFtable' border='1' style='width':100%>"; //starts the table tag
echo "<tr>
<td>Name</td>
<td>Vehicle</td>
<td>Licence Plate</td>
<td>In</td>
<td>Out</td>
<td>In</td>
<td>Out</td>
<td>Comments</td>
</tr>"; //sets headings
while($row = $result->fetch_assoc()) { //loops for each result
echo "<tr>
<td>".$row['name']."</td>
<td>".$row['vehicle']."</td>
<td>".$row['plate']. "</td>
<td><input type='text' size='5' maxlength='5' name='inTime' value='".$row['inTime']."' id='inTime' /></td>
<td><input type='text' name='outTime' value='".$row['outTime']."' id='outTime' /></td>
<td><input type='text' name='inTime2' value='".$row['inTime2']."' id='inTime2' /></td>
<td><input type='text' name='outTime2' value='".$row['outTime2']."' id='outTime2' /></td>
<td><input type='text' name='comments' value='".$row['comments']."' id='comments' /></td>
</tr>";
}
echo "</table>"; //closes the table
?>
<input type="submit" name="Save" value="Save" />
</fieldset>
</form>
The database connection is fine and working. Here is the php that handles the post:
if (isset($_POST['Save'])){
$name = $_POST['name'];
$vehicle = $_POST['car'];
$plate = $_POST['plate'];
$inTime = $_POST['inTime'];
$outTime = $_POST['outTime'];
$inTime2 = $_POST['inTime2'];
$outTime2 = $_POST['outTime2'];
$comments = $_POST['comments'];
$query = "UPDATE carLog SET inTime = '$inTime', outTime = '$outTime', inTime2 = '$inTime2', outTime2 = '$outTime2' WHERE plate = '$plate'";
$databaseConnection->query($query);

Note:
You only have five (5) input fields inside your while() loop, but you are trying to process eight (8) input fields in your carLog.php. So it will return undefine variables error.
Pass the input fields in array.
Inside the loop, hide the primary id of each car/vehicle in a hidden input (also in array).
Add this inside your while() loop:
/* ASSUMING vehicle_id IS THE PRIMARY ID OF YOUR carLog TABLE; JUST REPLACE IT WITH THE RIGHT COLUMN NAME */
echo '<input type="hidden" name="hidden_id[]" value="'.$row["vehicle_id"].'">';
You have to add [] in your input's name tags.
<td><input type='text' name='outTime[]' .....
Do it to the rest of your inputs.
Then on your carLog.php file, which process the input (at least use
*_real_escape_string to prevent SQL injections). We will be checking each input using for() loop:
if (isset($_POST['Save'])){
for($x = 0; $x< count($_POST["hidden_id"]); $x++){
$vehicleid = $databaseConnection->real_escape_string($_POST['hidden_id'][$x]);
$inTime = $databaseConnection->real_escape_string($_POST['inTime'][$x]);
$outTime = $databaseConnection->real_escape_string($_POST['outTime'][$x]);
$inTime2 = $databaseConnection->real_escape_string($_POST['inTime2'][$x]);
$outTime2 = $databaseConnection->real_escape_string($_POST['outTime2'][$x]);
$comments = $databaseConnection->real_escape_string($_POST['comments'][$x]);
$query = "UPDATE carLog SET inTime = '$inTime', outTime = '$outTime', inTime2 = '$inTime2', outTime2 = '$outTime2' WHERE vehicle_id = '$vehicleid'";
$databaseConnection->query($query);
} /* END OF FOR LOOP */
} /* END OF ISSET Save */
Since you are using mysqli_* already, consider using the prepared statement approach.

Related

SQL data displayed from a table to a textbox

I currently have a search screen to display results. A user can click on a link in that search screen to open a new window and view additional information. Currently i'm able to display the additional information as a table however I want to display the data in text boxes.
Currently my code to display the data ins a table is as follows: Code to get the id of the row that the user has clicked on
$id = $_GET['id'];
$sql = "SELECT user_id, name, age, address
FROM details
WHERE user_id= '".id."'";
$query = mysqli_query($connection, $sql);
$_SESSION['user_id'] = $id;?>
Code to display the data as a table:
<tr>
<th>name</th>
<th>age</th>
<th>address</th>
</tr>
<tbody>
<?php while ($row = mysqli_fetch_array($query)){ ?>
<tr>
<td><?php echo $row['name'] ?></td>
<td><?php echo $row['age'] ?></td>
<td><?php echo $row['address'] ?></td>
</tr>
</tbody>
I want to display the data in text boxes and its not as easy as I thought. I thought I could just changethe row to a text box as below.
<label for="name">Full Name:</label>
<input id="name" style="width: 150px; type="text" value="<?php echo $row['name']; ?>
Any pointers would be greatly appreciated.
As another has said you are open to abuse here but because anyone can type anything into the address bar as a get variable. Try this instead.
<?php
// First check you have the get, then if so retrieve it and run this till the end
if ($_GET) {
// Sanitize the get data
$id = mysqli_real_escape_string($connection, $_GET['id']);
$id = strip_tags($id);
$id = trim($id);
$id = urldecode($id);
$id = htmlspecialchars($id);
// Select the get data from your table
$select = mysqli_query($connection, "select user_id,name,age,address from details where user_id='$id'");
// Check if at least one record actually exists
if (mysqli_num_rows($select)>0) {
// Retrieve an array from your select, this will get all records for that ID so you may want to close the while loop before echoing the results in HTML if you have multiple records...
while ($row=mysqli_fetch_array($select)) {
$real_id = $row['user_id'];
$name = $row['name'];
$age = $row['age'];
$address = $row['address'];
// Display the results in HTML
echo "
<label for='id'>ID</label>
<input type='text' id='id' value='$real_id'>
<label for='name'>Name</label>
<input type='text' id='name' value='$name'>
<label for='age'>Age</label>
<input type='text' id='age' value='$age'>
<label for='address'>Address</label>
<input type='text' id='address' value='$address'>
";
}
}
}
mysqli_close($connection);
?>
Conclusions: if there is no GET data or if the GET data doesn't correspond to anything in your table nothing will happen.

how to update table row data with unique id?

code:
<?php
if(isset($_POST['save']))
{
$comment1 = $_POST['comment2'].",".date('Y-m-d');
$comment2 = $_POST['comment2'];
$id = $_POST['id'];
$query = "update enquires2 set comment1 = '$comment1', comment2 = '$comment2', s_date = '$s_datee' where id='$id'";
$result = mysqli_query($link,$query);
if($result==true)
{
echo "successfull";
}
else
{
echo "error!";
}
}
?>
<form method="post" name="myform">
<table>
<tr>
<th>comment1</th>
<th>comment2</th>
<th>Action</th>
</tr>
<?php
$sql = "select * from enquires2 ";
$result = mysqli_query($link,$sql);
while ($row = mysqli_fetch_array($result))
{
?>
<tr>
<td>
<input type='hidden' name='id' value='<?php echo $row['id']; ?>'>
</td>
<td>
<?php echo $row['comment1']; ?>
</td>
<td>
<input type='text' name='comment2' id='comment2' value=""/>
</td>
<td>
<input type ='submit' name='save' id='save' value='Save' />
</td>
</tr>
<?php
}
?>
</table>
</form>
In this code I want to update table enquires2 with unique id. In following image you see that table row having save button this is only one row similarly it have multiple row which having save button in each row. Now I want that when I click on save button of particular row only that row data will be update. How can I fix this problem ? Please help.
Thank You
You could use AJAX and jQuery to do this and send the data to a separate PHP file and assigning the $row['ID'] to a data-value attribute of the button,
$("#save-btn").click(function(){
id = $(this).attr(data-value);
***** rest of values here
$.ajax({
method: "GET",
data: {id: id, rest of: data here},
url: phpfile.php,
success: function(){
console.log("Success");
}
})
});
While in the PHP file you would take get the id like,
$_GET['id'], and same with the other values since we are using the GET method and then put them in the update query.
First of all, for security reason you need to change this query to a prepared statement see PHP MySQLI Prevent SQL Injection:
$id = $_POST['id'];
$query = "update enquires2 set comment1 = '$comment1', comment2 = $comment2', s_date = '$s_datee' where id='$id'";
$result = mysqli_query($link,$query);
This line is bad anyway, you are missing a opening quote for $comment2.
$query = "update enquires2 set comment1 = '$comment1', comment2 = $comment2', s_date = '$s_datee' where id='$id'";
Are you sure $link is an actual mysqli link?
As for the html part, you need to mkae one form for each record. See the link posted HTML: Is it possible to have a FORM tag in each TABLE ROW in a XHTML valid way?
alternatively you could do something bad like only adding the $id to evry field for every row (similar to:)
<input type ='submit' name='save[<?=$id;?>]' id='save' value='Save' />
and in the php code check witch key is set.
if(isset($_POST['save']) && is_array($_POST['save'])){
$id=key($_POST['save']);
}
You will need to replicate the bad thing for your comments as well but as a proof of concept you can run this snippet on phpfiddle.org
<?php
print_r($_POST);
if(isset($_POST['save']) && is_array($_POST['save'])){
echo key($_POST['save']);
}
?>
<html>
<form method='post'>
<input type='submit' name='save[1]' value='1' />
<input type='submit' name='save[2]' value='2' />
</form>
</html>
Wish i could provide you a really full answer but there's alot of work to be done on your code for it to be 'proper coding'. Again this becaome a matter of opinion beside the fact that your code is vunerable to sql injection and is NOT accepable.
Don't use your code at all for security vulnerability. Read more about sql injection Here. After all, For each row () create a form with a hidden input storing id of row .
I revised my code to make it work,create a nested table inside your td, so that tag will be accepted,
also see this link for a working reference,
HTML: Is it possible to have a FORM tag in each TABLE ROW in a XHTML valid way?
<?php
if(isset($_POST['save']))
{
$comment1 = $_POST['comment2'].",".date('Y-m-d');
$comment2 = $_POST['comment2'];
$id = $_POST['id'];
$query = "update enquires2 set comment1 = '$comment1', comment2 = '$comment2', s_date = '$s_datee' where id='$id'";
$result = mysqli_query($link,$query);
if($result==true)
{
echo "successfull";
}
else
{
echo "error!";
}
}
?>
<table>
<tr>
<th>comment1</th>
<th>comment2</th>
<th>Action</th>
</tr>
<?php
$sql = "select * from enquires2 ";
$result = mysqli_query($link,$sql);
while ($row = mysqli_fetch_array($result))
{
?>
<tr><td><table>
<form method="post" name="myform">
<tr>
<td>
<input type='hidden' name='id' value='<?php echo $row['id']; ?>'>
</td>
<td>
<?php echo $row['comment1']; ?>
</td>
<td>
<input type='text' name='comment2' id='comment2' value=""/>
</td>
<td>
<input type ='submit' name='save' id='save' value='Save' />
</td>
</tr>
</form>
</table>
</td>
</tr>
<?php
}
?>
</table>

Delete multiple mysql rows with check box not working

Here Is my problem: I do not get any error with my code but my problem is when i click the 'Delete Multiple' Button it does nothing not even reload the page.
Note: By The Way the redirect_to(); function i created so do not get confused by thinking that is a php function or anything
PHP Code:
display_errors(E_ALL);
if(isset($_POST['muldelete'])) {
$mul = $_POST['checkdelete'];
$sql = "DELETE FROM cmarkers WHERE id = " . $mul;
$result = mysqli_query($db, $sql);
redirect_to("elerts.php");
}
HTML Code:
<form action="elerts.php" method="post">
<table class="table table-striped">
<tr>
<td> </td>
<td>Date</td>
<td>Comment</td>
<td>Actions</td>
</tr>
<?php
$sql = "SELECT * FROM cmarkers";
$result = $db->query($sql);
while ($row = mysqli_fetch_assoc($result)) {
?>
<tr>
<td><input type="checkbox" name="checkdelete[]" value="<?php echo $row['id']; ?>" /></td>
<td><?php echo $row['date']; ?></td>
<td><?php echo $row['comment']; ?></td>
<td>DeleteEdit</td>
</tr>
<?php
}
?>
<input type="submit" name="muldelete" value="Delete Multiple" />
</table>
</form>
Thank You
If you need more info please let me know
First, your code contain some attention and placements errors.
input between <table> outer of td's is incorrect.
You can't make a multiple delete if you generate one form by value to
delete.
Fix them.
Getting Array of muldelete
To all the checked inputs, you must add the array field symbol
to clusterize the name "muldelete" to a post array.
<td><input type="checkbox" name="checkdelete[]" value="<?php $row['id']; ?>" /></td>
PHP side
Now you can fetch whole deletion array, like this:
if(!empty($_POST["muldelete"]))
{
$mul = join(',', $_POST['checkdelete']);
// Using IN() to make only one query for all records instead of multiple
// ex: IN(3, 4, 54, 8)
$query = "DELETE FROM cmarkers WHERE id IN(".$mul.")";
$result = mysqli_query($db, $query);
redirect_to("elerts.php");
}
Security
If ID's are integer value, you can prevent string injection into the sql query
$mul = array_map(function($id)
{
return intval($id);
}, $mul);
Your button is outside the <form></form> tags, so it is not related to the form elements or the form method at all. Instead of having a different form for each checkbox you should surround the entire table with the form tags thus ensuring that all the checkboxes and the button are in the same form.
<form method='post' action='elerts.php'>
<table class="table table-striped">
...all your table data including checkboxes...
<input type="submit" name="muldelete" value="Delete Multiple" />
</table>
</form>
I think because You are closing form tag earlier than submit button.
Try to put whole table into and should work.
PHP should looks like
display_errors(E_ALL);
if(isset($_POST['muldelete'])) {
$mul = implode(',',$_POST['checkdelete']);
$sql = "DELETE FROM cmarkers WHERE id IN(" . $mul.")";
$result = mysqli_query($db, $sql);
redirect_to("elerts.php");
}

Unable to update database table from php page

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...

Attempting to update results generated from a while loop

My main issue that I am running into is basically this:
I have a while loop that generates results from a query. With the results that have been generated, I want the ability to update the table the original query was from.
The query produces the expected results, but the table is not being updated when I click the REMOVE button. I am also trying to find a solution for the results to be updated after the UPDATE query executes...
<?php
$sql = "SELECT * FROM vehicles WHERE sold='n' ORDER BY year DESC";
$query = mysql_query($sql);
while ($row = mysql_fetch_array($query)) {
echo
"
<tr>
<td style='border-bottom-style:dotted;padding-top:10px;padding-bottom:10px;font-size:.9em'>",$row['year'],"</td>
<td style='border-bottom-style:dotted;padding-top:10px;padding-bottom:10px;font-size:.9em'>",$row['make'],"</td>
<td style='border-bottom-style:dotted;padding-top:10px;padding-bottom:10px;font-size:.9em'>",$row['model'],"</td>
<td style='border-bottom-style:dotted;padding-top:10px;padding-bottom:10px;font-size:.9em'><input type='submit' name='remove' value='REMOVE' style='background-color:#C33;color:white;padding:10px;border-radius:5px;width:70px'/></td>
</tr>";
if(isset($_POST['remove'])){
$removeSql = "UPDATE `table`.`vehicles` SET `display`='0' WHERE `vin`='{$row['vin']}'";
mysql_query($removeSql) or die('check that code dummy');
}
}
mysql_close($connection);
?>
That's a submit button, will not work without form tag. You can't do it this way.
You can write the remove code on a separate page and convert that submit button to normal button and pass vin id on click of that button and call that page using ajax.
Or if you don't know ajax and want to do it on that page itself then do it this way :
<?php
$sql = "SELECT * FROM vehicles WHERE sold='n' ORDER BY year DESC";
$query = mysql_query($sql);
while ($row = mysql_fetch_array($query)) {
echo
"
<tr>
<td style='border-bottom-style:dotted;padding-top:10px;padding-bottom:10px;font-size:.9em'>",$row['year'],"</td>
<td style='border-bottom-style:dotted;padding-top:10px;padding-bottom:10px;font-size:.9em'>",$row['make'],"</td>
<td style='border-bottom-style:dotted;padding-top:10px;padding-bottom:10px;font-size:.9em'>",$row['model'],"</td>
<td style='border-bottom-style:dotted;padding-top:10px;padding-bottom:10px;font-size:.9em'>
<form action="" method="POST">
<input type="hidden" name="vin_id" value="<?php echo $row['vin']; ?>">
<input type='submit' name='remove' value='REMOVE' style='background-color:#C33;color:white;padding:10px;border-radius:5px;width:70px'/>
</form></td>
</tr>";
}
if(isset($_POST['remove'])){
$removeSql = "UPDATE `table`.`vehicles` SET `display`='0' WHERE `vin`='".$_POST['vin_id']."'";
mysql_query($removeSql) or die('check that code dummy');
}
mysql_close($connection);
?>

Categories