PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi,
I try to do the following but without any success.
/* code start here */
Where delete_record is a php function that will delete the record in the SQL table.
So this will generate a table where the last column is only the term "delete" shown where the user can click the delete link to delete the current record in the row.
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
It's not possible like that. All PHP code is performed well before the browser receives data most often. You will need to make a link to a script with the necessary information needed to perform your task.
You're definitely thinking in terms of JavaScript right there.
PHP is server-side... Links don't affect the scripts, but you can use links to give variables form one script to the next. For example:
The most common way (and the way taught in most tutorials) is to use the row ID from the database as a query string var then pass it back to the calling page and use that pass back as your trigger to delete.
<?php
if (isset($_GET['item'])) {
// Check, validate and ensure integrity of the value here
// Then assign and use
$delete = $_GET['id'];
$sql = "DELETE FROM `table` WHERE `id` = $delete";
// Continue processing
}
// The rest of your code that selects and displays
// with links to basename(__FILE__) . '?item=' . $row['id']
?>