Jump to content

Recommended Posts

This is nearly working but im missing something. I have printed out a DB table into HTML on the page and have a link to the ID to delete a record. It is refreshing but not actually deleting?

 

SEND PAGE:

 

<?php

 

include'E:\domains\s\domain.com\user\private\mysql_connect.php';

mysql_select_db("pix", $con);

 

$result = mysql_query("SELECT * FROM mailing_list");

 

echo "<table border='1'>

<tr>

<th>ID</th>

<th>Name</th>

<th>Email Address</th>

<th>Interest</th>

<th>Country</th>

</tr>";

 

while($row = mysql_fetch_array($result))

  {

  echo "<tr>";

  echo "<td>" . $row['ID'] . "</td>";

  echo "<td>" . $row['name'] . "</td>";

  echo "<td>" . $row['email'] . "</td>";

  echo "<td>" . $row['interest'] . "</td>";

  echo "<td>" . $row['country'] . "</td>";

  echo "<td>" .'<a href="delete_mail.php?id='.$row['ID'].'">Delete</a>'. "</td>";

  echo "</tr>";

  }

echo "</table>";

 

mysql_close($con);

?>

 

DELETE method:

 

<?

// Connect database.

include'E:\domains\s\domain\user\private\mysql_connect.php';

 

// Get values from form.

$id=$_GET['ID'];

 

// Do delete statement.

mysql_query("delete from mailing_list where ID='$id'");

 

// Close database connection

mysql_close();

 

// Redirect

header("location:view_mailing_list.php");

 

?>

 

What am I missing?!

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/183223-delete-record-using-id-from-database/
Share on other sites

You should be learning php, developing php code, and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON in your master php.ini so that php will help you. (Confirm the actual settings using a phpinfo() statement in case the php.ini that you are changing is not the one that php is using.) You will save a ton of time.  There would have been an undefined index error message in your code concerning $_GET['ID'] that would have alerted you to the fact that is not being set because it does not match the ?id being put on the end of the URL.

Im getting this error

 

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' on line 16

 

does not like something about this line:

 

header("location:view_mailing_list.php");

 

bear with me, i am learning php. Thanks.

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.