Jump to content

Recommended Posts

I have finaly got my removing recods page working, but i do have one problem...

 

i have a delete button which goes to a new php page which contains the DELETE FROM, this deletes the record automaticaly. There are two paths which i could choose from the problem is i am stuck on both of them.

 

1. a link that will activate the delete code.

2. once the record has been deleted then it will automaticaly go back the the first page.

 

can any one help me here please?

The link for deleting the record will be

<a href="delete.php?id=x">Delete</a>

change X to your records id.

 

Now in delete.php you'd do

if(isset($_GET['id']) && is_numeric($_GET['id']))
{
     $id = (int) $_GET['id'];
     
     // dont forget to connect to mysql

     $query = "DELETE FROM table WHERE id=$id";
     mysql_query($query);
}

 

You can redirect a visitor using header. But you can only use the function before your output any text/html.

i cant change the id to x, becuase i am passing a var through it, here is my code

 

 

 

  <?php

$host="------"; // Host name

$username="------"; // Mysql username

$password="------"; // Mysql password

$db_name="--------"; // Database name

$tbl_name="forum_question"; // Table name

 

// Connect to server and select databse.

mysql_connect("$host", "$username", "$password")or die("cannot connect");

mysql_select_db("$db_name")or die("cannot select DB");

 

$id=$_GET['id'];

?>

><a href="<? mysql_query("DELETE FROM forum_question WHERE id='$id'"); ?>">yes</a></p>

I didn't say change your ids to x. I meant replace the x with your records id number.

 

<a href="<? mysql_query("DELETE FROM forum_question WHERE id='$id'"); ?>">

You can not pass PHP code within a link. Look at my code example.

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.