Bigg Brawler Posted February 3, 2012 Share Posted February 3, 2012 Hi All, I have a simple 'delete record' code that is not working. Would someone please take a gander at it and let me know if they see anything wrong that would prevent it from actually deleting a record. <?php //connects to the database include ('db_connect.php'); //post variable $pk = $_POST['pk']; //MySQL code to query ---- 'contacts' = table & 'primary_key' = record id # $deleteContact = "DELETE FROM `contacts` WHERE `primary_key` = ".$pk." LIMIT 1"; //excutes query to MySQL $res = mysqli_query($link,$deleteContact); //close connection to database mysqli_close($link); ?> Any help would be great. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/256343-php-simple-delete-record-issue/ Share on other sites More sharing options...
Cobra23 Posted February 3, 2012 Share Posted February 3, 2012 What's $link assigned to ? I think there's no need for it but your using mysqli. I'm always working with MySQL Quote Link to comment https://forums.phpfreaks.com/topic/256343-php-simple-delete-record-issue/#findComment-1314141 Share on other sites More sharing options...
Bigg Brawler Posted February 3, 2012 Author Share Posted February 3, 2012 $link is in my 'db_connect.php' include... it's the connection to my database. $link = mysqli_connect('hostname', 'username', 'password', 'database'); Quote Link to comment https://forums.phpfreaks.com/topic/256343-php-simple-delete-record-issue/#findComment-1314142 Share on other sites More sharing options...
Maq Posted February 3, 2012 Share Posted February 3, 2012 Are you positive your query is correct (print it out)? Does that record actually exist? Have you debugged by printing out potential sql errors? (http://php.net/manual/en/mysqli.error.php) Quote Link to comment https://forums.phpfreaks.com/topic/256343-php-simple-delete-record-issue/#findComment-1314146 Share on other sites More sharing options...
Bigg Brawler Posted February 3, 2012 Author Share Posted February 3, 2012 seeing how it wasn't a blatant "this is wrong" I researched the actual $pk = $_POST['pk'] and found even though I thought the variable was being posted.... it wasn't. The code is correct and want to thank you guys for helping me figure out it wasn't the php code but the code being posted TO php. Quote Link to comment https://forums.phpfreaks.com/topic/256343-php-simple-delete-record-issue/#findComment-1314153 Share on other sites More sharing options...
Maq Posted February 3, 2012 Share Posted February 3, 2012 seeing how it wasn't a blatant "this is wrong" I researched the actual $pk = $_POST['pk'] and found even though I thought the variable was being posted.... it wasn't. The code is correct and want to thank you guys for helping me figure out it wasn't the php code but the code being posted TO php. You might want to check to see if that POST is set and display feedback appropriately. At least you know what's wrong. If this is resolved please mark as solved. Quote Link to comment https://forums.phpfreaks.com/topic/256343-php-simple-delete-record-issue/#findComment-1314175 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.