I have a dynamic table that list some items from my MySQL table, just like this:
<?php
$output='';
$sql1=mysql_query("SELECT * FROM table1 ORDER BY item")or die(mysql_error());
$sql1n=mysql_num_rows($sql1);
if($sql1n>=1){
while($row=mysql_fetch_array($sql1)){
$item_num=$row['item_num'];
$item_category=$row['item_category'];
$item_name=$row['item_name'];
output .='<tr>';
output .='<td>'.$item_num.'</td>';
output .='<td>'.$item_category.'</td>';
output .='<td>'.$item_name.'</td>';
output .='<td><a href="#">Delete</a></td>';
output .='</tr>';
}else{
output .='Items not found!";
}
?>
Now I do have my HTML page
<body>
<table width="100%" id="panel" border="0" cellspacing="0" cellpadding="3" class="table2">
<tr>
<td>Item #</td>
<td>Category</td>
<td>Name</td>
</tr>
<?php echo $output; ?>
</table>
</body>
I will have the list of Items, Category and Name and an extra column with Delete option if there are some data inside of the database, otherwise, it will return Items Not Found! I would like to click in the Delete link and pass the variables $item_num and $item_category referent to the actual row to a jquery function that will send to the following PHP file, without refresh the actual file, and return a message saying that the item has been deleted successfully!
Delete-Item.php
<?php
include ('dataconfig.php');
if((isset($_POST['item_num']))and(isset($_POST['item_category']))){
$item_num=$_POST['item_num'];
$item_category=$_POST['item_category'];
$sql_delete=mysql_query("DELETE FROM table1 WHERE item_num='$item_num' AND item_category='$item_category'")or die(mysql_error());
}
?>
I don't know the best way to build a jQuery function that is going to do that and I will really appreciate any help that can lead me to finish this task.
Thanks
<input name="item_category" value="' or 1 = 1 or '" />unixwiz.net/techtips/sql-injection.html