Du laver et "slette-link": <a href="delete.php?id=1">Slet</a>
PÅ dette link har du angivet den post_id, som du vil slette i databasen - her bare kaldt id.
På siden delete.php laver du så følgende: <? // -> forbindelse til database $delete = mysql_query("DELETE FROM forum_post_benzinspar WHERE post_id= ".$_REQUEST["id"]); ?>
Du henter alle indlæggene ud fra databasen, og her skal du samtidig bede den om at indlægge id'en i linket.
Det kan gøres på mange forskellige måder, og jeg vil gerne have lov at se lidt af din kode, for at jeg ikke skal komme med et forslag der er helt anderledes, end det du har lavet...
<?php //check for required info from the query string if (!$_GET[topic_id]) { header("Location: topiclist.php"); exit; }
//connect to server and select database $conn = mysql_connect("mysql.unoeuro.com", "vivaa_dk", "6MTY18QA") or die(mysql_error()); mysql_select_db("vivaa_dk_db",$conn) or die(mysql_error());
//verify the topic exists $verify_topic = "select topic_title from forum_topics_benzinspar where topic_id = $_GET[topic_id]"; $verify_topic_res = mysql_query($verify_topic, $conn) or die(mysql_error());
if (mysql_num_rows($verify_topic_res) < 1) { //this topic does not exist $display_block = "<P><em>You have selected an invalid topic. Please <a href=\"topiclist.php\">try again</a>.</em></p>"; } else { //get the topic title $topic_title = stripslashes(mysql_result($verify_topic_res,0, 'topic_title'));
//gather the posts $get_posts = "select post_id, post_text, date_format(post_create_time, '%b %e %Y at %r') as fmt_post_create_time, post_owner from forum_posts_benzinspar where topic_id = $_GET[topic_id] order by post_create_time asc"; $get_posts_res = mysql_query($get_posts,$conn) or die(mysql_error());
//create the display string $display_block = " <P>Showing posts for the <strong>$topic_title</strong> topic:</p>
<?php //check for required info from the query string if (!$_GET[topic_id]) { header("Location: topiclist.php"); exit; }
//connect to server and select database $conn = mysql_connect("XXX", "XXX", "XXX") or die(mysql_error()); mysql_select_db("vivaa_dk_db",$conn) or die(mysql_error());
//delete post
if ($_GET[id]) { $delete = mysql_query("DELETE FROM forum_post_benzinspar WHERE post_id= ".$_GET[id]); }
//verify the topic exists $verify_topic = "select topic_title from forum_topics_benzinspar where topic_id = $_GET[topic_id]"; $verify_topic_res = mysql_query($verify_topic, $conn) or die(mysql_error());
if (mysql_num_rows($verify_topic_res) < 1) { //this topic does not exist $display_block = "<P><em>You have selected an invalid topic. Please <a href=\"topiclist.php\">try again</a>.</em></p>"; } else { //get the topic title $topic_title = stripslashes(mysql_result($verify_topic_res,0, 'topic_title'));
//gather the posts $get_posts = "select post_id, post_text, date_format(post_create_time, '%b %e %Y at %r') as fmt_post_create_time, post_owner from forum_posts_benzinspar where topic_id = $_GET[topic_id] order by post_create_time asc"; $get_posts_res = mysql_query($get_posts,$conn) or die(mysql_error());
//create the display string $display_block = " <P>Showing posts for the <strong>$topic_title</strong> topic:</p>
- - - - - <?php //check for required info from the query string if (!$_GET[topic_id]) { header("Location: topiclist.php"); exit; }
//connect to server and select database $conn = mysql_connect("XXX", "XXX", "XXX") or die(mysql_error()); mysql_select_db("vivaa_dk_db",$conn) or die(mysql_error());
//delete post
if ($_GET[id]) { $delete = mysql_query("DELETE FROM forum_post_benzinspar WHERE post_id= ".$_GET[id]); }
//verify the topic exists $verify_topic = "select topic_title from forum_topics_benzinspar where topic_id = $_GET[topic_id]"; $verify_topic_res = mysql_query($verify_topic, $conn) or die(mysql_error());
if (mysql_num_rows($verify_topic_res) < 1) { //this topic does not exist $display_block = "<P><em>You have selected an invalid topic. Please <a href=\"topiclist.php\">try again</a>.</em></p>"; } else { //get the topic title $topic_title = stripslashes(mysql_result($verify_topic_res,0, 'topic_title'));
//gather the posts $get_posts = "select post_id, post_text, date_format(post_create_time, '%b %e %Y at %r') as fmt_post_create_time, post_owner from forum_posts_benzinspar where topic_id = $_GET[topic_id] order by post_create_time asc"; $get_posts_res = mysql_query($get_posts,$conn) or die(mysql_error());
//create the display string $display_block = " <P>Showing posts for the <strong>$topic_title</strong> topic:</p>
Kan man så ikke blot bruge: Koden: if ($_GET[topic_id]) { $delete = mysql_query("DELETE FROM forum_topics_benzinspar WHERE post_id= ".$_GET[topic_id]); }
og Linket: <a href=\"topiclist.php?topic_id=$_GET[topic_id]\">DELETE POST</A>
Ikke nødvendigt jeg klarede opgaven selv :) God tur...
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.