Jump to content

Passing a $id variable (probably a simple answer(!))


HughbertD

Recommended Posts

Hi,

 

I am looping information from my database into an html table, and have an "Edit" and "Delete" link at the end of each row.

 

When I click delete, it does not do anything, but also, the $id value does not appear in the url.

 

What am I doing wrong? I think it has something to do with $GET, am I right?

 

Here is my code (minus some CSS bits and pieces):


<?php
$usr = "root";
$pwd = "michael";
$db = "jostark";
$host = "localhost";
$cid = mysql_connect($host,$usr,$pwd);
if (!$cid) { echo("ERROR: " . mysql_error() . "\n");	}
mysql_select_db("jostark", $cid);

if ($task=="del") {

	$SQL = " DELETE FROM manager ";
	$SQL = $SQL . " WHERE managerID = $id ";
	mysql_query($SQL, $cid);

}
echo("$id");

?>


<?php

$SQL = " select * from manager, placement where manager.companyID = placement.companyID;";
$retid = mysql_query($SQL, $cid);
if (!$retid) { echo( mysql_error()); }
else {
	echo "<P><TABLE CELLPADDING=4>\n";
	?>
	<tr>
		<td>Name</td>
		<td>Company</td>
		<td>Email</td>
	</tr>
	<?php
	while ($row = mysql_fetch_array($retid)) {
		$firstName = $row["manFirstName"];
		$lastName = $row["manLastName"];
		$company = $row["compName"];
		$email = $row["manEmail"];
		$id = $row["id"];

		echo ("<TR>");
		echo ("<TD>$firstName $lastName</TD>\n");
		echo ("<TD>$company</TD>\n");
		echo ("<TD>$email</TD>\n");
		echo ("<TD><A HREF=\"manageedit.php?id=$id\">Edit</A></TD>");
		echo ("<TD><A HREF=\"displayManager.php?id=$id&task=del\">Delete</A></TD>");
		echo ("</TR>");
	}
	echo ("</TABLE>");
}
?>

 

Thank you to anyone that can help out, this has been driving me nuts!

Link to comment
Share on other sites

I think I understand so I put:

 

if ($task=="del") {
	$id = $_GET['id'];
	$SQL = " DELETE FROM manager ";
	$SQL = $SQL . " WHERE managerID = $id ";
	mysql_query($SQL, $cid) or die (mysql_error());

}

 

This extracts the id= part from my url, but I don't think it is actually doing "del" at all.

 

Is this why I need to use a $GET on the $TASK too?

 

I have the $task at the top of the code, does this make a difference?

Link to comment
Share on other sites

I got it!

 

I was putting the GET for the task inside the If statement of the task function.

 

So I guess it never got around to getting it out the url.

 

Thanks Adam and thanks Rajiv!

 

I appreciate the help

 

P.S. No, I put in "echo $id;" underneath mysql_query and it doesn't return anytthing., it appears to be working though.

 

Is this something to worry about?

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.