0
<? 
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","******","******");
	
//select which database you want to edit
mysql_select_db("*******"); 

//If cmd is not hit
if(!isset($cmd)) 
{
   //display all the news
   $result = mysql_query("select * from Cars"); 
   
   //run the while loop that grabs all the news scripts
   while($r=mysql_fetch_array($result)) 
   { 
      //grab the title and the ID of the enws
      $Title=$r["Title"];//take out the title
      $Id=$r["Id"];//take out the id
     
      echo "<a href='delete.php?cmd=delete&Id=$Id'>$Title - Delete</a>";
      echo "<br>";
    }
}
?>

<?
if($cmd=="delete")
{
    $sql = "DELETE FROM Cars WHERE Id=$Id";
    $result = mysql_query($sql);
    echo "Row deleted!";
}
?>

It shows up all the information, however when I press delete it does not do anything. Any suggestions?

Thanks

4
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by rajarajan07
0

YOU Must write follwowing code in delete.php

if($_GET['cmd']=="delete")
{    $sql = "DELETE FROM Cars WHERE Id={$_GET['Id']}";    
      $result = mysql_query($sql);    echo "Row deleted!";
}
0

It seems you are not reading the $cmd value from the request

Add this in the top of your script.

$cmd = $_REQUEST;

hope it helps you

<? 
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","******","******");
	
//select which database you want to edit
mysql_select_db("*******"); 

//If cmd is not hit
if(!isset($cmd)) 
{
   //display all the news
   $result = mysql_query("select * from Cars"); 
   
   //run the while loop that grabs all the news scripts
   while($r=mysql_fetch_array($result)) 
   { 
      //grab the title and the ID of the enws
      $Title=$r["Title"];//take out the title
      $Id=$r["Id"];//take out the id
     
      echo "<a href='delete.php?cmd=delete&Id=$Id'>$Title - Delete</a>";
      echo "<br>";
    }
}
?>

<?
if($cmd=="delete")
{
    $sql = "DELETE FROM Cars WHERE Id=$Id";
    $result = mysql_query($sql);
    echo "Row deleted!";
}
?>

It shows up all the information, however when I press delete it does not do anything. Any suggestions?

Thanks

0

First get the value to process as utrivedi said

<?
   $command=$_GET['cmd'];
   $key=$_GET['id'];
   if ($command=='delete')
 {
    $sql = "DELETE FROM Cars WHERE Id=$key";
    $result = mysql_query($sql);
    echo "Row deleted!";
}
?>

Edited by rajarajan07: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.