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!

I now have the variable displaying in the url, like so:

 

http://localhost/joStark/css/displayManager.php?id=3&task=del

 

It was due to me having the field name for the managerID wrong in the table

 

However, it still does not perform a delete

 

I am not using a POST for this, should I be?

you use $_get to obtain information out of a URL. For example

 

www.adam.co.uk?adam=4

<?php
$adam  = $_get['adam'];
$echo $adam;
?>

 

this will return 4. $_Post gets information from a form. This information is sent to the form directly.

 

 

 

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?

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?

 

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.