nieuwssysteem-met-mysql
Gesponsorde koppelingen
PHP script bestanden
Hier een simpel nieuwssysteem met mysql....
news_list.php
news_edit.php
news_new.php zou je dan nog moeten beveiligen zodat niet iedereen bestanden kan wissen....voor de rest kan je hem makkelijk aanpassen naar eigen wensen....
commentaar hoor ik graag :)
style.css
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<head>
<style>
body {
background-color: #262626;
color: #FFFFFF;
font-family: Verdana;
font-size: 8pt;
}
table {
background-color: #000000;
}
td {
background-color: #262626;
color: #FFFFFF;
font-family: Verdana;
font-size: 8pt;
}
.top {
background-color: #FF7722;
color: #000000;
font-size: 7pt;
}
input,textarea {
background-color: #4D4D4D;
color: #FFFFFF;
font-family: Verdana;
font-size: 8pt;
border: 0px;
}
.bottom {
background-color: #4d4d4d;
color: ;
}
</style>
</head>
<style>
body {
background-color: #262626;
color: #FFFFFF;
font-family: Verdana;
font-size: 8pt;
}
table {
background-color: #000000;
}
td {
background-color: #262626;
color: #FFFFFF;
font-family: Verdana;
font-size: 8pt;
}
.top {
background-color: #FF7722;
color: #000000;
font-size: 7pt;
}
input,textarea {
background-color: #4D4D4D;
color: #FFFFFF;
font-family: Verdana;
font-size: 8pt;
border: 0px;
}
.bottom {
background-color: #4d4d4d;
color: ;
}
</style>
</head>
global.inc.php
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
<?
$host = "localhost"; // je mysql host
$name = ""; // je mysql username
$pass = ""; // je mysql password
$data = "news"; // je mysql database
$connect = mysql_connect ("$host","$name","$pass") or die
("The database appears to be down");
$select = mysql_select_db ("$data",$connect) or die
("The database appears to be down");
?>
$host = "localhost"; // je mysql host
$name = ""; // je mysql username
$pass = ""; // je mysql password
$data = "news"; // je mysql database
$connect = mysql_connect ("$host","$name","$pass") or die
("The database appears to be down");
$select = mysql_select_db ("$data",$connect) or die
("The database appears to be down");
?>
news.php
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
include("style.css");
include("global.inc.php");
$sql= "SELECT * FROM news ORDER BY news_datetime DESC";
$res= mysql_query($sql);
?>
<?
while($news = mysql_fetch_array($res)){
//Opmaak van datum
$unixtime = strtotime($news['news_datetime']);
?>
<table width="400" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td class="top">
<b> <?php echo $news['news_header'] ?></b>
</td>
<td class="top" align="right">
<? echo date("d-m-Y",$unixtime) ?>
</td>
</tr>
<tr>
<td class="bottom" colspan="2">
<?php echo $news['news_main'] ?>
</td>
</tr>
</table>
<br>
<?php
}
mysql_close();
?>
</td>
</tr>
</table>
include("style.css");
include("global.inc.php");
$sql= "SELECT * FROM news ORDER BY news_datetime DESC";
$res= mysql_query($sql);
?>
<?
while($news = mysql_fetch_array($res)){
//Opmaak van datum
$unixtime = strtotime($news['news_datetime']);
?>
<table width="400" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td class="top">
<b> <?php echo $news['news_header'] ?></b>
</td>
<td class="top" align="right">
<? echo date("d-m-Y",$unixtime) ?>
</td>
</tr>
<tr>
<td class="bottom" colspan="2">
<?php echo $news['news_main'] ?>
</td>
</tr>
</table>
<br>
<?php
}
mysql_close();
?>
</td>
</tr>
</table>
news_edit.php
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?
include("global.inc.php");
include("style.css");
$SQL_news="SELECT * FROM news WHERE id=" . $_GET['id'];
$news_result=mysql_query($SQL_news);
$news=mysql_fetch_array($news_result);
mysql_close();
$news['news_main'] = eregi_replace('<br[[:space:]]*/?[[:space:]]*>', "\n", $news['news_main']);
?>
<html>
<head>
<title></title>
</head>
<body>
<form action=news_list.php method=post>
<table border="0" cellspacing="1" cellpadding="0">
<tr>
<td>Titel:</td>
<td>
<input type="text" name="news_header" value="<?php echo $news['news_header'] ?>" size="19" maxlength="120">
</td>
</tr>
<tr>
<td>Datum/tijd:</td>
<td>
<input type="text" name="news_datetime" value="<?php echo $news['news_datetime'] ?>" size="19" maxlength="19">
</td>
</tr>
<tr>
<td>Inhoud:</td>
<td>
<textarea name="news_main" rows="6" cols="45"><?php echo $news['news_main'] ?></textarea>
</td>
</tr>
<tr>
<td colspan="2">
<input type="hidden" name="id" value="<?php echo $news['id'] ?>">
<input type="hidden" name="action" value="update">
<input type="submit" name="Submit" value="OK">
</td>
</tr>
</table>
</form>
</body>
</html>
include("global.inc.php");
include("style.css");
$SQL_news="SELECT * FROM news WHERE id=" . $_GET['id'];
$news_result=mysql_query($SQL_news);
$news=mysql_fetch_array($news_result);
mysql_close();
$news['news_main'] = eregi_replace('<br[[:space:]]*/?[[:space:]]*>', "\n", $news['news_main']);
?>
<html>
<head>
<title></title>
</head>
<body>
<form action=news_list.php method=post>
<table border="0" cellspacing="1" cellpadding="0">
<tr>
<td>Titel:</td>
<td>
<input type="text" name="news_header" value="<?php echo $news['news_header'] ?>" size="19" maxlength="120">
</td>
</tr>
<tr>
<td>Datum/tijd:</td>
<td>
<input type="text" name="news_datetime" value="<?php echo $news['news_datetime'] ?>" size="19" maxlength="19">
</td>
</tr>
<tr>
<td>Inhoud:</td>
<td>
<textarea name="news_main" rows="6" cols="45"><?php echo $news['news_main'] ?></textarea>
</td>
</tr>
<tr>
<td colspan="2">
<input type="hidden" name="id" value="<?php echo $news['id'] ?>">
<input type="hidden" name="action" value="update">
<input type="submit" name="Submit" value="OK">
</td>
</tr>
</table>
</form>
</body>
</html>
news_list.php
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
include("global.inc.php");
include("style.css");
if(isset($_GET['action'])) $action=$_GET['action'];
if(isset($_POST['action'])) $action=$_POST['action'];
if($action=="delete"){
$id=$_GET['id'];
$news_SQL_del="DELETE FROM news WHERE id=$id";
$bool=mysql_query($news_SQL_del);
if($bool==1) echo "<SCRIPT LANGUAGE=JavaScript>window.alert('Bericht is gewist')</SCRIPT>";
if($bool<>1) echo "<SCRIPT LANGUAGE=JavaScript>window.alert('Bij het wissen is een fout opgetreden')</SCRIPT>";
}
if($action=="insert"){
$news_main=$_POST['news_main'];
$news_header=$_POST['news_header'];
$news_datetime=$_POST['news_datetime'];
$news_main=nl2br($news_main);
$news_main=eregi_replace("\n", "", $news_main);
$news_SQL_insert="INSERT INTO news (news_header,news_datetime,news_main) VALUES ('$news_header','$news_datetime','$news_main')";
$bool=mysql_query($news_SQL_insert);
if($bool==1) echo "<SCRIPT LANGUAGE=JavaScript>window.alert('Bericht toegevoegd')</SCRIPT>";
if($bool<>1) echo "<SCRIPT LANGUAGE=JavaScript>window.alert('Bij het toevoegen van het bericht is een fout opgetreden')</SCRIPT>";
}
if($action=="update"){
$id=$_POST['id'];
$news_main=$_POST['news_main'];
$news_header=$_POST['news_header'];
$news_datetime=$_POST['news_datetime'];
$news_main=nl2br($news_main);
$news_main=eregi_replace("\n", "", $news_main);
$news_SQL_update="UPDATE news SET news_header='$news_header',news_main='$news_main',news_datetime='$news_datetime' WHERE id='$id'";
$bool=mysql_query($news_SQL_update);
if($bool==1) echo "<SCRIPT LANGUAGE=JavaScript>window.alert('Bericht is bewerkt')</SCRIPT>";
if($bool<>1) echo "<SCRIPT LANGUAGE=JavaScript>window.alert('Bij het bewerken van het bericht is een fout opgetreden')</SCRIPT>";
}
$sql="SELECT * FROM news ORDER BY news_datetime DESC";
$res=mysql_query($sql);
?>
<html>
<head>
<title></title>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td class="top">Datum/tijd</td>
<td class="top">Titel</td>
<td class="top">Inhoud</td>
<td class="top">Wissen/Bewerken</td>
</tr>
<?
while($news=mysql_fetch_array($res)){
$unixtime = strtotime($news['news_datetime']);
?>
<tr bgcolor="#F9F9F9">
<td><?php echo date("d-m-Y",$unixtime) ?></td>
<td><?php echo $news['news_header'] ?></td>
<td><?php echo $news['news_main'] ?></td>
<td><a href=news_list.php?id=<?php echo $news['id'] ?>&action=delete>Wissen</a>
<a href=news_edit.php?id=<?php echo $news['id'] ?>>Bewerken</a></td>
</tr>
<?php
}
mysql_close();
?>
</table>
</td>
</tr>
</table>
</body>
</html>
include("global.inc.php");
include("style.css");
if(isset($_GET['action'])) $action=$_GET['action'];
if(isset($_POST['action'])) $action=$_POST['action'];
if($action=="delete"){
$id=$_GET['id'];
$news_SQL_del="DELETE FROM news WHERE id=$id";
$bool=mysql_query($news_SQL_del);
if($bool==1) echo "<SCRIPT LANGUAGE=JavaScript>window.alert('Bericht is gewist')</SCRIPT>";
if($bool<>1) echo "<SCRIPT LANGUAGE=JavaScript>window.alert('Bij het wissen is een fout opgetreden')</SCRIPT>";
}
if($action=="insert"){
$news_main=$_POST['news_main'];
$news_header=$_POST['news_header'];
$news_datetime=$_POST['news_datetime'];
$news_main=nl2br($news_main);
$news_main=eregi_replace("\n", "", $news_main);
$news_SQL_insert="INSERT INTO news (news_header,news_datetime,news_main) VALUES ('$news_header','$news_datetime','$news_main')";
$bool=mysql_query($news_SQL_insert);
if($bool==1) echo "<SCRIPT LANGUAGE=JavaScript>window.alert('Bericht toegevoegd')</SCRIPT>";
if($bool<>1) echo "<SCRIPT LANGUAGE=JavaScript>window.alert('Bij het toevoegen van het bericht is een fout opgetreden')</SCRIPT>";
}
if($action=="update"){
$id=$_POST['id'];
$news_main=$_POST['news_main'];
$news_header=$_POST['news_header'];
$news_datetime=$_POST['news_datetime'];
$news_main=nl2br($news_main);
$news_main=eregi_replace("\n", "", $news_main);
$news_SQL_update="UPDATE news SET news_header='$news_header',news_main='$news_main',news_datetime='$news_datetime' WHERE id='$id'";
$bool=mysql_query($news_SQL_update);
if($bool==1) echo "<SCRIPT LANGUAGE=JavaScript>window.alert('Bericht is bewerkt')</SCRIPT>";
if($bool<>1) echo "<SCRIPT LANGUAGE=JavaScript>window.alert('Bij het bewerken van het bericht is een fout opgetreden')</SCRIPT>";
}
$sql="SELECT * FROM news ORDER BY news_datetime DESC";
$res=mysql_query($sql);
?>
<html>
<head>
<title></title>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td class="top">Datum/tijd</td>
<td class="top">Titel</td>
<td class="top">Inhoud</td>
<td class="top">Wissen/Bewerken</td>
</tr>
<?
while($news=mysql_fetch_array($res)){
$unixtime = strtotime($news['news_datetime']);
?>
<tr bgcolor="#F9F9F9">
<td><?php echo date("d-m-Y",$unixtime) ?></td>
<td><?php echo $news['news_header'] ?></td>
<td><?php echo $news['news_main'] ?></td>
<td><a href=news_list.php?id=<?php echo $news['id'] ?>&action=delete>Wissen</a>
<a href=news_edit.php?id=<?php echo $news['id'] ?>>Bewerken</a></td>
</tr>
<?php
}
mysql_close();
?>
</table>
</td>
</tr>
</table>
</body>
</html>
news_new.php
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?
include("global.inc.php");
include("style.css");
?>
<html>
<head>
<title></title>
</head>
<body>
<form action=news_list.php method=post>
<table border="0" cellspacing="1" cellpadding="0">
<tr>
<td>Titel:</td>
<td>
<input type="text" name="news_header" size="50" maxlength="120">
</td>
</tr>
<tr>
<td>Datum/tijd:</td>
<td>
<input type="text" name="news_datetime" value="<?php echo date("Y-m-d") ?>" size="19" maxlength="19">
</td>
</tr>
<tr>
<td>Inhoud:</td>
<td>
<textarea name="news_main" rows="6" cols="45"></textarea>
</td>
</tr>
<tr>
<td colspan="2">
<input type="hidden" name="action" value="insert">
<input type="submit" name="Submit" value="OK">
</td>
</tr>
</table>
</form>
</body>
</html>
include("global.inc.php");
include("style.css");
?>
<html>
<head>
<title></title>
</head>
<body>
<form action=news_list.php method=post>
<table border="0" cellspacing="1" cellpadding="0">
<tr>
<td>Titel:</td>
<td>
<input type="text" name="news_header" size="50" maxlength="120">
</td>
</tr>
<tr>
<td>Datum/tijd:</td>
<td>
<input type="text" name="news_datetime" value="<?php echo date("Y-m-d") ?>" size="19" maxlength="19">
</td>
</tr>
<tr>
<td>Inhoud:</td>
<td>
<textarea name="news_main" rows="6" cols="45"></textarea>
</td>
</tr>
<tr>
<td colspan="2">
<input type="hidden" name="action" value="insert">
<input type="submit" name="Submit" value="OK">
</td>
</tr>
</table>
</form>
</body>
</html>