Jump to content

Deleting a row from table


slj90

Recommended Posts

Hi, I am trying to create a 'delete' button to delete a row in a table, the code I have is as follows

 

 

<?php  
include "connection.php"; 
// if id provided, then delete that record  
$CustomerID=$_GET['id'] ;  
// create query to delete record  
$query = "DELETE FROM customer WHERE id = '$CustomerID' ";  
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());  
  // see if any rows were affected 
if (mysql_affected_rows() > 0) {  
  //If so , return to calling page using header function and HTTP_REFERER 
    header("Location: {$_SERVER['HTTP_REFERER']}");     
  }  
  else {  
    // print error message  
    echo "Error in query: $query. ".mysql_error(); 
    exit; 
  } 
?> 

 

I get the error..Error in query: DELETE FROM customer WHERE id = '1' . Unknown column 'id' in 'where clause'

 

It is getting the ID# from the URL.. http://localhost/deleteAction.php?id=1

 

Can you see why this isn't working?

 

Thanks

 

 

Link to comment
https://forums.phpfreaks.com/topic/184739-deleting-a-row-from-table/
Share on other sites

I'm getting confused with 'id' and 'CustomerID'..

 

 

CREATE TABLE Customer(
CustomerID	int(11) NOT NULL auto_increment,
Firstnames	VARCHAR(10) NOT NULL,
Surname	VARCHAR(15) NOT NULL,
Username	VARCHAR(12) NULL,
Email		VARCHAR(20) NULL,
Password	VARCHAR(12) NULL,
PRIMARY KEY (CustomerID)
);

 

Thanks

 

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.