Jump to content

Deleting data from a table


frilund

Recommended Posts

<html>
<head>
<meta charset="iso-8859-1" />

<title> Hjem </title>
</head>
<body>

<?php
include 'config.php';

session_start();


if(!session_is_registered(mitbrugernavn)){

?>

<form action="tjek.php" method="post">
Brugernavn: <input type="text" name="mitbrugernavn"> </p>
Kodeord:    <input type="password" name="mitkodeord"> </p>
<input type="submit" value="Login">

</form>
<?php

}
else

{
	?>
	 </p>
Du er nu logget ind! Velkommen <? print $_SESSION['mitbrugernavn']; ?>
 </p>
<li>
<a href="logout.php"> Log ud </a>
</li>
</p>
<li>
<a href="opret.php"> Opret ny konto </a>
</li>
<li>
<a href="medlemmer.php">Oprettede kontoer</a>
</li> </p>

<?
$con = mysql_connect("localhost","HIDDEN","HIDDEN");
if (!$con) {
  die('Kunne ikke tilslutte: ' . mysql_error());
}

mysql_select_db("HIDDEN", $con);
$result = mysql_query("select count(*) FROM medlemmer");
$row = mysql_fetch_array($result);

$total = $row[0];
echo "Antal medlemmer: " . $total;

}


?>
</p>
</p>

<?php

$aktion= $_GET['action'];

if($aktion == "slet"){
mysql_query("DELETE FROM news WHERE name=$nName");	
	echo "Nyheden er nu slettet";
	echo ('<meta http-equiv="refresh" content="3;url=tilfoj-nyheder.php">'); 
}
else
{
echo "Kunne ikke slette nyheden";
}

$loadNews = mysql_query("SELECT * FROM news ORDER BY id DESC") or die(mysql_error());


if(mysql_num_rows($loadNews) == 0) {

echo "Der er ikke blevet tilføjet nogle nyheder.";


} else {


while($showNews = mysql_fetch_array($loadNews)) {

$nName = stripslashes($showNews["name"]); 
$nAuthor = stripslashes($showNews["author"]);
$nText = nl2br(stripslashes($showNews["text"]));
$nDate = $showNews["date"]; 

?>
<div>
<div align="center" style="border-style:solid; margin:3px; width:400px; height:auto;">
<b> <?php print "$nName"; ?> </b><br /> 
<i>Skrevet af <? print "$nAuthor ,"; ?> d. <?php print "$nDate"; ?> </i><br /> 
<? print "$nText"; 
 ?>

 
<br /><br />
</div>
</br>
<? 
if(session_is_registered(mitbrugernavn)){
?>
<form action='?action=slet' method="POST">

<input type="submit" value="slet">

</form>
<?
}

?>
</div>
<?
}

}

if(session_is_registered(mitbrugernavn)){
echo "<a href=\"tilfoj-nyheder.php\" title=\"Tilføj nyhed\">Tilføj nyhed</a>";
}
?>

</body>



</html>

Hello! I am trying to make a delete button for my news, but I have no idea how it works.

The code for the button starts at line 68.

 

PS. Im new here correct me if posting this wrong! Thanks in advance!

Link to comment
Share on other sites

this reply has nothing to do with your question, but the code you have is so out of date i'm surprised it even runs. here's a list of problems in it -

 

1) the session_start() statement needs to come before you output any characters to the browser

 

2) session_is_registered was depreciated 10-11 years ago and has been removed as of php5.4. you should test if the $_SESSION variable isset() instead.

 

3) the mysql_ database library functions are depreciated starting in php5.5. all new code should be written using mysqli or PDO database libraries.

 

4) if you find yourself using stripslashes() when you retrieve data from a database, either the data was improperly escaped when it was inserted or magic_quotes_runtime is on and should be turned off (all magic_quotes_ functionality is removed as of php5.4.)

 

wherever you found this code or learned php, the information is out of date. it would be best if you started over using current and up-to-date php standards.

Edited by mac_gyver
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.