Hello Guys,

I want to delete a record from my saved.php
which has a code,

<td><a href=\"delete.php?id=$ID\">delete</a></td>

Which gets the link as
http://localhost/delete.php?id=8022

I then have a delete.php file,

which has this code,

<?php

if(isset $_GET['id']))
{
$id = $_GET['ID'];
$con = mysql_connect("localhost","t","123456");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("t", $con);

mysql_query("delete FROM t_table where ID='$ID'");

}

?>

But i get an error,

Parse error: parse error, expecting `'('' in C:\wamp\www\delete.php on line 3

Thank you for the help :)

if(isset ($_GET))
{
//code here
}

juist missing "(" for isset.

if(isset $_GET)) is missing a parenthesis, should be

if(isset($_GET['id']))

After doing that i get the following error,

Notice: Undefined index: ID in C:\wamp\www\delete.php on line 5

Notice: Undefined variable: ID in C:\wamp\www\delete.php on line 14

i understand i have ID as undefined so where do i define it?

Thank you

$id = $_GET;

Variables are case-sensitive, so use $id instead of $ID

<?php

if(isset($_GET['ID']))
{
$con = mysql_connect("localhost","r","123456");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("r", $con);
$ID = $_GET['ID'];
mysql_query("delete FROM r_table where ID='$ID'");

}

?>

After doing the following, i get a blank page, which i am no to bothered about, but why isnt it deleting the row which is phpmyadmin is as ID.

ANy help would be apericiated

echo ur query did you get any results


echo $mysql_query;

copy that query and run in phpmyadmin,, did it works or not

if id is an integer, you may need to remove the apostrophes.

Hello,

First of all which one is that i change as i have tried it and it doesnt work.

just blank page and when i check it in mysql, it still shows that row.

Any help will be apericiated.

Member Avatar for spthorn

Here's the consensus:

if(isset($_GET['id']))
{
$con = mysql_connect("localhost","r","123456");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("r", $con);
$id = $_GET['id'];
mysql_query("delete FROM r_table where ID=$id");
echo $mysql_query;
}

If you take the echo'd string and run it in phpmysql, do you get an error? What is it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.