Jump to content

Delete/change newsitems


RDLyTN

Recommended Posts

Hi,

 

I'm working on a newssystem, I already can add newsitems to the database but i can't change or delete them. Does anyone have an idea what I'm doing wrong?

 

CODE:

 

ADD NEWSITEM:

<?php

require("constants.php");

 

$connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS);

if(!$connection) {

die("Database connection failed!" . mysql_error());

}

 

$db_select = mysql_select_db(DB_NAME, $connection);

if(!$db_select) {

die("Database connection failed!" . mysql_error());

}

 

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title>AIKIBDUO - Nieuwsadmin</title>

<link rel="stylesheet" type="text/css" href="css/style.css">

<META HTTP-EQUIV="imagetoolbar" CONTENT="no">

</head>

<body>

 

<table border="0" cellspacing="17" width="100%"><tr><td class="tekst">

<div class="titel">Nieuws administratie</div><br>

<div class="links">Bericht toevoegen</div>

<hr noshade>

<div align="right" class="small"><a href="nieuws_admin2.php">berichten aanpassen of verwijderen</a></div>

<br>

 

<?php

if(isset($_POST['voegtoe']))

{

$datum = $_POST['datum'];

$onderwerp = $_POST['onderwerp'];

$bericht = $_POST['bericht'];

 

mysql_query("INSERT INTO nieuws (datum, onderwerp, bericht)

VALUES ('".$datum."', '".$onderwerp."', '".$bericht."')")

or die (mysql_error());

 

echo 'Het nieuws is succesvol opgeslagen.';

}

else

{

?>

<form action="<?=$_SERVER['PHP_SELF']?>" method="POST">

<table cellspacing="10" width="100%">

<tr>

<td class="tekst" valign="top"><b>Datum:</b></td>

<td><input type="text" class="formke" name="datum" size="30" value="<?php echo date("d/m/y"); ?>"></td>

</tr>

<tr>

<td class="tekst" valign="top"><b>Onderwerp:</b></td>

<td><input type="text" class="formke" name="onderwerp" size="30"></td>

</tr>

<tr>

<td class="tekst" valign="top"><b>Bericht:</b></td>

<td><textarea cols="70" rows="20" class="formke" name="bericht"></textarea></td>

<tr>

<td class="tekst"> </td>

<td><input type="submit" class="form" name="voegtoe" value="Voeg toe"></td>

</tr>

</table>

</form>

<?php

}

?>

 

</td></tr></table>

<br>

 

</body>

</html>

<?php

mysql_close(DB_SERVER, DB_USER, DB_PASS);

?>

 

DELETE NEWSITEM

 

<?php

require("constants.php");

 

$connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS);

if(!$connection) {

die("Database connection failed!" . mysql_error());

}

 

$db_select = mysql_select_db(DB_NAME, $connection);

if(!$db_select) {

die("Database connection failed!" . mysql_error());

}

 

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title>AIKIBUDO - Nieuwsadmin</title>

<link rel="stylesheet" type="text/css" href="css/style.css">

<META HTTP-EQUIV="imagetoolbar" CONTENT="no">

</head>

<body>

 

<SCRIPT LANGUAGE="JavaScript">

 

function doedelete(numb){

if (confirm("Ben je zeker dat je dit bericht wil verwijderen?"))

{

window.document.submitform.del.value = numb;

window.document.submitform.submit();

}

}

 

</SCRIPT>

 

<?php

 

if (isset($del) && $del >= 0)

{

mysql_query("DELETE FROM nieuws

WHERE id = '$del'");

}

?>

?>

 

<table border="0" cellspacing="17" width="100%">

<tr>

<td class="tekst">

<div class="titel">Nieuws administratie</div><br>

<div class="links">Berichten aanpassen/verwijderen</div>

<hr noshade>

<br><br>

 

<div align="center">

 

<table border=0 cellpadding="0" cellspacing="5" width="100%">

<tr>

<td class="tekst"><b>Datum</b></td>

<td class="tekst" width="1"><font color="#c0c0c0">|</font></td>

<td class="tekst"><b>Onderwerp</b></td>

<td class="tekst" width="1"><font color="#c0c0c0">|</font></td>

<td class="tekst" align="right"><b>Bewerken</b></td>

</tr>

<tr>

<td colspan="5" bgcolor="#c0c0c0"><img src="images/niks.gif" height="1" width="1" alt=""></td>

</tr>

<?php

$result = mysql_query("SELECT id, onderwerp, datum

FROM nieuws

ORDER BY id DESC");

while($show_msg = mysql_fetch_array($result))

{

echo( "<tr>\n\t<td class=\"tekst\" colspan=\"2\">$show_msg[datum]</td>\n" .

"\t<td class=\"tekst\" colspan=\"2\">$show_msg[onderwerp]</td>\n" .

"\t<td class=\"tekst\" align=\"right\"><a href=\"nieuws_edit.php?id=$show_msg[id]\"><img src=\"images/edit.gif\" width=\"19\" height=\"14\" alt=\"Bewerk dit bericht\" border=\"0\"></a><a href=\"\" OnClick=\"Javascript:doedelete('$show_msg[id]');return false;\"><img src=\"images/delete.gif\" width=\"19\" height=\"14\" alt=\"Verwijder dit bericht\" border=\"0\"></a></td></tr>\n");

}

?>

<tr>

<td colspan="5" bgcolor="#c0c0c0"><img src="images/niks.gif" height="1" width="1" alt=""></td>

</tr>

</table>

</div>

 

 

<form method="post" name="submitform">

<input type="hidden" name="del" value="-1">

</form>

 

</td>

</tr>

</table>

<br>

</body>

</html>

<?php

mysql_close(DB_SERVER, DB_USER, DB_PASS);

?>

 

CHANGE NEWSITEM

<?php

require("constants.php");

 

$connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS);

if(!$connection) {

die("Database connection failed!" . mysql_error());

}

 

$db_select = mysql_select_db(DB_NAME, $connection);

if(!$db_select) {

die("Database connection failed!" . mysql_error());

}

 

?>

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title>AIKIBUDO - Nieuwsadmin</title>

<link rel="stylesheet" type="text/css" href="css/style.css">

<META HTTP-EQUIV="imagetoolbar" CONTENT="no">

</head>

<body>

 

<?php

if(isset($_POST['voegtoe'])) {

mysql_query("UPDATE nieuws

SET bericht = '".$_POST['bericht']."'

WHERE id ='".$_POST['id']."'")

or die ("fout bij het opslaan van je bericht in de databank");

}

$result = mysql_query("SELECT *

FROM nieuws

WHERE id = '$id'");

$show_msg = mysql_fetch_array($result);

?>

 

<table border="0" cellspacing="17" width="100%">

<tr>

<td class="tekst">

<div class="titel">Nieuws administratie</div><br>

<div class="links">Bericht aanpassen</div>

<hr noshade>

<br><br>

 

<form method="POST" name="submitform" action="nieuws_admin2.php">

<table cellspacing="10" width="100%">

<tr>

<td class="tekst" valign="top"><b>Onderwerp:</b></td>

<td><input type="text" class="formke" name="onderwerp" size="30" value="<?=$show_msg[onderwerp]?>"></td>

</tr>

<tr>

<td class="tekst" valign="top"><b>Bericht:</b></td>

<td><textarea cols="70" rows="20" class="formke" name="bericht"><?=$show_msg[bericht]?></textarea></td>

<tr>

<td class="tekst"> </td>

<td><input type="submit" class="form" name="voegtoe" value=" Wijzig "> <input type="reset" class="form" value=" reset "></td>

</tr>

</table>

<input type="hidden" value="<?=$id?>" name="id">

</form>

</td>

</tr>

</table>

 

</body>

</html>

<?php

mysql_close(DB_SERVER, DB_USER, DB_PASS);

?>

     

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.