Jump to content

Recommended Posts

Hi All,

I have the following two part query.

The initial query runs correctly and returns the records to the screen, then selecting a record for deletion, the program should then delete the chosen record from the database and then display the details of the remaining records to screen, either for checking or to delete another record.

 

The queries run without error however the chosen record is not being deleted form the database.

 

Any help would be much appreciated

 

Regards

 

Hamish

<?php
ob_start();

// Connect database.
@include("opendbincludeA.php");
// ***** This part will process when you Click on "Delete" button *****
// Check, if you clicked "Delete" button
if($_POST['Submit'])
{
// Get parameters from form.
$id=$_POST['id'];
$password=$_POST['password'];
$name=$_POST['name'];
$permission=$_POST['permission'];

// Do delete statement.

@mysql_query("DELETE FROM User  WHERE id=$id");

   die("DELETE FROM User  WHERE id=$id");
   // Re-direct this page 
   $id=$_POST['id'];
   header("location: DeleteUser.php?id=$id");
   exit;

}else{
// ************* End delete part *************

// *** Select data to show on text fields in form. ***

// Get id parameter (GET method) from DeleteUser.php
$id=$_GET['id'];

// Get records in all columns from table where column id equal in $id and put it in $result.
$result=mysql_query("select * from User where id='$id'");

// Split records in $result by table rows and put them in $row.
$row=mysql_fetch_assoc($result);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>User Details</title>
<link href="Course_Buttons/UniStyle.css" rel="stylesheet" type="text/css" />
</head>
<body>


<!-- set this form to POST method and target this form to itself ($PHP_SELF;)-->
<form id="form1" name="form1" method="post" action="<?php echo $PHP_SELF; ?>">
<p>
User ID:
<input name="id" type="text" id="id" value="<?php echo $row['id']; ?>"/>
Delete Details As Required
<br /><br />
<br  />
Name :
<!-- name of this text field is "CourseName" -->
<input name="name" type="text" id="name" value="<?php echo $row['name']; ?>"/>

Password :
<!-- name of this text field is "UCAS_Code" -->
<input name="password" type="text" id="password" value="<?php echo $row['password']; ?>"/>


<br  />
Permission :
<!-- name of this text field is "PLTitle" -->
<input name="permission" type="text" id="permission" value="<?php echo $row['permission']; ?>"/>
<br  />




<p>
<input type="submit" name="delete" value="delete" />
</p>
</form>

<?php

// Close database connection.
}

ob_end_flush();
mysql_close();

?>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/50483-delete-query-not-deleting/
Share on other sites

Hi jitesh,

If I run the code with echo statement as below,it runs as before without error, but does not re display returned query nor does it delete the record.

Regards

 

Hamish

@mysql_query("DELETE FROM User  WHERE id=$id");
echo "DELETE FROM User  WHERE id=$id";

   //die("DELETE FROM User  WHERE id=$id");
   // Re-direct this page 
   $id=$_POST['id'];
   header("location: DeleteUser.php?id=$id");
   exit;

 

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.