Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/256343-php-simple-delete-record-issue/
Share on other sites

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.

 

 

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.