I was wondering how I could go about turning this add entry link in to a delete entry link? Any help would be appreciated.
if (CAN_EDIT){
echo '<i>'.$announcements[$x]['page_edit']='<a href="index.php?id='.$announcements[$x]['page_id'].'&act=edit">edit entry</a></i><br />';
if ($announcements[$x]['page_edit']>0){}
}
I understand about using
mysql_query DELETE FROM (table name) WHERE (item name)
I am just not sure how to implement it and make it a link.
It’s really up to how your application handles the requests. The edit link code you posted shows that two parameters are being passed to the PHP:
idandact. Both will be available within$_GETin PHP when the link is clicked.From that, we can infer that your code is checking
$_GET['act']to decide what to do. If it is equal to'edit', you’ll probably fetch some data from the DB (for records whereidequals$_GET['id']), then render an edit form.Using that same logic, you should create a link with
id=N&act=delete(whereNis an actual ID). Then in PHP you check if the value of$_GET['act']is'delete', then run the SQL query to delete the row with the ID passed.Also, make sure to do a little research on SQL injection — you should not use
$_GETor$_POSTvalues directly in the query, as that would make your app vulnerable to injection. Take a look at themysql_real_escape_stringfunction on the PHP manual.