Dhananjay Gupta Dhananjay Gupta - 11 months ago 53
SQL Question

Passing php variables

I am creating a user interface for managing a database. Each entry has two radio buttons, one for validation (and subsequent emailing to concerned authorities) and one for deleting the entry. The code is given below, and the bold parts are the ones which concern this functionality.
A couple of questions:
1) Is it possible to do so without the form attribute? If so, how would I do it?

2) With the form attribute, I use 'handle.php' to delete each entry. The syntax in the 'handle.php' includes this line

$sql="DELETE FROM rti WHERE ID=x"; //x here is the ID number to delete.

Now, how do I pass the value of the ID as well from my interface, so that the above line of code deletes the entry corresponding to the button that was pressed?

* {
margin: 0px;
padding: 0px;

div.topbar {
position: relative;
background-color: black;
height: 45px;
text-align: center;
font-family: Calibri;
font-size: 30px;
padding-top: 10px;

div.topbar img {
position: absolute;
left: 10px;
top: 0px;

div.topbar span {
color: white;

div.container {
background-color: #a5a5a5;
width: 100%;
height: 100%;
color: white;

div.data {
padding: 20px;

table {
background-color: #b1b1b1;
border-collapse: collapse;

th, td {
text-align: center;
border: solid 1px black;
margin: 0px;

th.one {
width: 50px;

width: 150px;

th.three {
width: 75px;

th.four {
width: 200px;

div.validation {
background-color: #b5b5b5;
width: 200px;
height: 100%;
position: relative;
left: 1100px;
bottom: 300%;
text-align: center;
border-left: solid 1px black;

<div class = "topbar"><img src="logo.png"><span>RTI DATABASE</span></div>
<div class = "container">
<div class ="data">
$conn=mysql_connect($servername, $username, $password) or die ("Error connecting to mysql server: ".mysql_error());
$dbname = 'bsp';
mysql_select_db($dbname, $conn) or die ("Error selecting specified database on mysql server: ".mysql_error());
$sql="SELECT * FROM rti";
$result=mysql_query($sql) or die ("Query to get data from firsttable failed: ".mysql_error());
echo "<table>";
echo "<tr>";
echo '<th class="one">ID</th>
<th class="two">Name</th>
<th class="three">Board</th>
<th class="four">Query</th>
<th class="five">Validate</th>
<th class="six">Delete</th>
<th class="seven">Submit</th>';

echo "</tr>";
while ($row=mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>$id</td>
**<form action='handle.php' method='POST'><td><input type='radio' name='option' value='validate'></td>
<td><input type='radio' name='option' value='delete'></td>
<td><input type='submit' value='Submit' name='submit'></form></td>";
echo "</tr>";**

echo "</table><br>";

**<form action='handle.php' method='POST'><td><input type='radio' name='option' value='validate'></td>
   <td><input type='radio' name='option' value='delete'>
  <input type='hidden' name="id" value='".$id."'> 
   <td><input type='submit' value='Submit' name='submit'></form></td>";

In handle.php:

$id = $_POST['id'];