I have this code that is displayed in a jquery dialog .load()'ed from a php script
$sql = '
SELECT
*
FROM
table
WHERE
id="'.$id.'"
';
$query = mysql_query($sql);
while($rows = mysql_fetch_array($query)) {
echo "Category: <input type='text' name='category[]' value=".$rows['category']." />";
}
this is part of a form that is posted to an external script to insert/update the db. The problem开发者_开发知识库 im having is how can I delete that column onclick by adding an a href "delete" after the input to be echoed, effectively deleting it from the db?
while($rows = mysql_fetch_array($query)) {
echo "Category: <input type='text' name='category[]' value=".$rows['category']." />";
echo "<a href="UrlWhereCodeOfDleteToBEWrite?task=delete&cat=".$rows['category'].">Delete</a>";
}
In file the above link will redirect write as
if(isset($_GET['task']) && $_GET['task'] == 'delete'){
if(!isset($_GET['cat'])){
die('Invalid cat to delete');
}
$sql = "DELETE FROM tableName WHERE columnName = '".$_GET['cat']."' ";
mysql_query($sql);
}
精彩评论