fbm Posted March 2, 2009 Share Posted March 2, 2009 Hi, I am trying to pass an ID from one page to another but getting into problems. I have a page which generates a table of all my clients i have added to the DB <?php $result = mysql_query("SELECT * FROM clients ORDER BY id ASC"); while($row = mysql_fetch_array($result)) { echo "<tr>\n"; echo "<td class='row_id'>".$row['id']."</td>\n"; echo "<td class='row'>".$row['company']."</td>\n"; echo "<td class='row'>".$row['primary_contact']."</td>\n"; echo "<td class='row'><a href='mailto:".$row['primary_email']."'>".$row['primary_email']."</a></td>\n"; echo "<td class='row'>".$row['primary_phone']."</td>\n"; echo "<td class='row'>\n"; echo "<ul>\n"; echo "<li class='view'><a href='clients_view.php&id=".$row['id']."'><span>view</span></a></li>\n"; echo "<li class='edit'><a href='clients_edit.php&id=".$row['id']."'><span>edit</span></a></li>\n"; echo "<li class='delete'><a href='process_delete_client&id=".$row['id']."'><span>delete</span></a></li>\n"; echo "</ul>\n"; echo "</td>\n"; echo "</tr>\n"; } ?> At the bottom of this code there is 3 links, view, edit, delete. I want to use these links to link to a new page and pass the Row ID to the next page. With the code above my link appears as this in HTML http://localhost/fbmcrm/manage/process_delete_client&id=2 i have also tried it with .php before the $id= but get the same problem. I have a page called process_delete_client.php which contains this <?php include "includes/header.php"; ?> <div id="page_content"> <div id="sub_menu"></div> <div id="content"> <?php mysql_query("DELETE FROM clients WHERE id='".$_GET['id']."'")or die(mysql_error()); echo "<div align='center'>"; echo "Client sucessfully removed from the database"; echo "<META HTTP-EQUIV=Refresh CONTENT='5; URL=clients_list.php'> "; echo "</div>"; ?> </div> </div> <?php include "includes/footer.php"; ?> But when i click the links in my client list table i get error page not found because the URL has the $id= on the end. How do i pass the ID to the next page for processing? Cheers Rick Link to comment https://forums.phpfreaks.com/topic/147557-solved-how-to-pass-an-id-from-db-to-another-page-in-a-link/ Share on other sites More sharing options...
phpdragon Posted March 2, 2009 Share Posted March 2, 2009 your link with the id needs to be like this http://localhost/fbmcrm/manage/process_delete_client.php?id=$id Link to comment https://forums.phpfreaks.com/topic/147557-solved-how-to-pass-an-id-from-db-to-another-page-in-a-link/#findComment-774594 Share on other sites More sharing options...
Yesideez Posted March 2, 2009 Share Posted March 2, 2009 In the script that is being called in the URL you need to grab the contents of the ID field using $_GET. $id=intval($_GET['id']); EDIT: Didn't notice you're already grabbing the ID field later on in the code - as mentioned, replace the & for a ? Link to comment https://forums.phpfreaks.com/topic/147557-solved-how-to-pass-an-id-from-db-to-another-page-in-a-link/#findComment-774595 Share on other sites More sharing options...
fbm Posted March 2, 2009 Author Share Posted March 2, 2009 thanks guys, now working Onto the edit and view pages now Link to comment https://forums.phpfreaks.com/topic/147557-solved-how-to-pass-an-id-from-db-to-another-page-in-a-link/#findComment-774597 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.