Jump to content

[SOLVED] DELETE RECORDS


barryflood22

Recommended Posts

New problem, iv got the database adding new records, and now I want it to display all of the records that are there buy name and id number, then i want u to be able to type in the id number of the customer u wish to delete and it shoudl delete it, sounds good buts its not actually deleting the record. it says it does, but its not doing it.

 

customer-modify.php

------------------------

 

<a href="index.php">< back</a>
<br /><br />
<?php

// This file contains the database access information. This file also establishes a connection to MySQL and selects the database.

// Set the database access information as constants.
$DBhost = "localhost";
$DBuser = "root";
$DBpass = "";
$DBName = "bf-customer";
$table = "customer";
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");

@mysql_select_db("$DBName") or die("Unable to select database $DBName");

?>


<?php
//This file do the actual insert in the database after the connection is established.

$query="SELECT * FROM customer";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

echo "<br />";
echo "<b><u>Enter ID of customer to delete</u></b>";
echo "<br /><br />";

$i=0;
while ($i < $num) {
$id=mysql_result($result,$i,"id");
$name=mysql_result($result,$i,"name");
$address=mysql_result($result,$i,"address");
$postcode=mysql_result($result,$i,"postcode");
$telephone=mysql_result($result,$i,"TelephoneNumber");
$emailaddress=mysql_result($result,$i,"EmailAddress");
$type=mysql_result($result,$i,"Type");
$Appointment=mysql_result($result,$i,"Appointment");

echo "ID: $id, ";
echo "$name<br>"; 

echo "<br />";

$i++;
}

echo "<br />";
?>

<form action="customer-modify-process.php" method="post">
ID: <input type="text" name="id" value=""><br>
<input type="Submit" value="Delete">
</form>

 

 

 

 

customer-modify-process.php

------------------------------------

 

<a href="index.php">< back</a>
<br /><br />

<?php
// Set the database access information as constants.
$DBhost = "localhost";
$DBuser = "root";
$DBpass = "";
$DBName = "bf-customer";
$table = "customer";

mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");

@mysql_select_db("$DBName") or die("Unable to select database $DBName");


// the 'insert' that will insert the data as a new row into the table under the respective columns.
mysql_query("DELETE FROM customer where id = '$id'") 
or die(mysql_error());  

echo "<br />";
echo "Data Deleted!";



?>

Link to comment
Share on other sites

u sure you're entering the right ID? i had the same issue today... then i suddenly found out that the ID's wasnt what I thought they were =) go into your table and take a look at what the ID's are... but then again... i havent even worked with MySQL for half a week yet =)

Link to comment
Share on other sites

change:

 

<form action="customer-modify-process.php" method="post">

 

to

 

<form action="customer-modify-process.php?id="<?php echo $_POST['id']; ?>"" method="post">

 

Then add to customer-modify-process.php:

 

$id = $_GET['id']

 

The problem is you are not sending an id to the second page. You have 2 ways to solve this - hidden inputs (best option) or via the URL (less secure)

Link to comment
Share on other sites

now im getting the following whenever i hit the delete button :

 

 

Parse error: syntax error, unexpected T_STRING in C:\wamp\www\hoff_godd\customer-modify-process.php on line 20

 

 

line 20 is mysql_query("DELETE FROM customer where id = '$id'")

 

<a href="index.php"><- back</a>
<br />
<br />

<?php

$DBhost = "localhost";
$DBuser = "root";
$DBpass = "";
$DBName = "customer";
$table = "customer";


mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");

@mysql_select_db("$DBName") or die("Unable to select database $DBName");

$id = $_GET['id']

mysql_query("DELETE FROM customer where id = '$id'") 
or die(mysql_error());  

echo "<br />";
echo "Data Deleted!";



?>

 

 

Link to comment
Share on other sites

<a href="index.php">< back</a>
<br /><br />

<?php
// Set the database access information as constants.
$DBhost = "localhost";
$DBuser = "root";
$DBpass = "";
$DBName = "bf-customer";
$table = "customer";

mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");

@mysql_select_db("$DBName") or die("Unable to select database $DBName");

$id = $_POST['id']; //add this line

// the 'insert' that will insert the data as a new row into the table under the respective columns.
mysql_query("DELETE FROM customer where id = '$id'") 
or die(mysql_error());  

echo "<br />";
echo "Data Deleted!";



?>

Link to comment
Share on other sites

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.