slj90 Posted December 11, 2009 Share Posted December 11, 2009 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 More sharing options...
rajivgonsalves Posted December 11, 2009 Share Posted December 11, 2009 id column does not exist in the customer table. must be something else customerid ? Link to comment https://forums.phpfreaks.com/topic/184739-deleting-a-row-from-table/#findComment-975240 Share on other sites More sharing options...
Deoctor Posted December 11, 2009 Share Posted December 11, 2009 can u paste the sql dump of the table structure. Link to comment https://forums.phpfreaks.com/topic/184739-deleting-a-row-from-table/#findComment-975241 Share on other sites More sharing options...
slj90 Posted December 11, 2009 Author Share Posted December 11, 2009 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 Link to comment https://forums.phpfreaks.com/topic/184739-deleting-a-row-from-table/#findComment-975243 Share on other sites More sharing options...
rajivgonsalves Posted December 11, 2009 Share Posted December 11, 2009 $query = "DELETE FROM customer WHERE CustomerID = '$CustomerID' "; Link to comment https://forums.phpfreaks.com/topic/184739-deleting-a-row-from-table/#findComment-975244 Share on other sites More sharing options...
slj90 Posted December 11, 2009 Author Share Posted December 11, 2009 Thank you for all your help tonight Link to comment https://forums.phpfreaks.com/topic/184739-deleting-a-row-from-table/#findComment-975248 Share on other sites More sharing options...
rajivgonsalves Posted December 11, 2009 Share Posted December 11, 2009 Your welcome please click topic solved if you think its solved Link to comment https://forums.phpfreaks.com/topic/184739-deleting-a-row-from-table/#findComment-975250 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.