Jump to content

[SOLVED] How to pass an ID from DB to another page in a link?


fbm

Recommended Posts

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

 

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 ?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.