Weekendje verveling = verder met leren van sitebuilding
In deze tutorial zal ik je uitleggen hoe je een simpel nieuwssysteem maakt.
Na deze TUT heb je een nieuwssysteem met MYSQL en Reacties.
Eerst hebben we 2 tabellen nodig voor database waar al de nieuwsberichten en reacties komen.
noem je database: "nieuwssysteem" o.i.d.
Query voor nieuws:
Query voor reacties:
We gaan een formulier maken waarmee we nieuws met kunnen toevoegen in de tabel nieuws.
maak een bestand: nieuwstoevoegen.php
nieuws toevoegen
Nu kan je dus berichten toevoegen in de database maar we moeten de berichten kunnen zien.
gebruik de functie SELECT
maak: Nieuws.php
Wat we nu nog missen is de pagina waar je reacties met kan toevoegen en een pagina waar je de comments kunt lezen.
Het probleem dat sommige mensen hebben is dat ze niet weten hoe je de comments kunt laten selecteren bij het juiste nieuwsbericht.
Wel, we maken dus een kolom bij de tabel nieuwscomments met de naam nieuwsid
Als we dan een comments toevoegen kan je het id van het nieuwsbericht in die kolom opslagen en kan je zo het de comments selecteren bij het gepaste nieuwsbericht.
Nu gaan we verder met de pagina.
postcomment.php
Het laatste (
)is de pagina waar je de reacties kunt lezen.
nieuwscomments.php
Het nieuwssysteem is eindelijk af
Je kan eventueel nog een admin pagina maken met verwijder en wijzig functie en er een loginsysteem op zetten maar mag je lekkur zelf doen
.
Succes, wijziging/fout? laat het even weten!
In deze tutorial zal ik je uitleggen hoe je een simpel nieuwssysteem maakt.
Na deze TUT heb je een nieuwssysteem met MYSQL en Reacties.
Eerst hebben we 2 tabellen nodig voor database waar al de nieuwsberichten en reacties komen.
noem je database: "nieuwssysteem" o.i.d.
Query voor nieuws:
CREATE TABLE nieuws (
id int(10) auto_increment not null default 0,
datum varchar(20) not null,
bericht text not null,
emailadres varchar(60) not null,
onderwerp varchar(60) not null,
naam varchar(30) not null,
primary key(id)) Query voor reacties:
CREATE TABLE reacties (
id int(10) auto_increment not null default 0,
nieuwsid int(10) not null,
datum varchar(20) not null,
tijd varchar(10) not null,
bericht text not null,
emailadres varchar(60) not null,
naam varchar(30) not null,
primary key(id)) We gaan een formulier maken waarmee we nieuws met kunnen toevoegen in de tabel nieuws.
maak een bestand: nieuwstoevoegen.php
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #FF8000]//Eerst connecten we met de database [/COLOR]
[URL="http://www.php.net/mysql_connect"]mysql_connect[/URL] [COLOR= #007700]([/COLOR][COLOR= #DD0000]"....."[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]"....."[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"....."[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//host, inlog, passwoord [/COLOR]
[URL="http://www.php.net/mysql_select_db"]mysql_select_db[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"nieuwssysteem"[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//databasenaam
//De datum instellen in het Nederlands! [/COLOR]
[COLOR= #0000BB]$arraymaand[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Januari"[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]"Februari"[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]"Maart"[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]"April"[/COLOR][COLOR= #007700],[/COLOR]
[COLOR= #DD0000]"Mei"[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]"Juni"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"Juli"[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]"Augustus"[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]"September"[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]"Oktober"[/COLOR][COLOR= #007700],[/COLOR]
[COLOR= #DD0000]"November"[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]"December"[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$datum[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/date"]date[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"j"[/COLOR][COLOR= #007700]) .[/COLOR] [COLOR= #0000BB]$arraymaand[/COLOR][COLOR= #007700][[/COLOR][URL="http://www.php.net/date"]date[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]" n"[/COLOR][COLOR= #007700]) -[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700]] .[/COLOR] [URL="http://www.php.net/date"]date[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]" Y"[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$bericht[/COLOR][COLOR= #007700]=[/COLOR] [URL="http://www.php.net/addslashes"]addslashes[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$bericht[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//slashes toevoegen voor vermijden errors
//Is alles ingevuld?[/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]submit[/COLOR][COLOR= #007700]])
{[/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]bericht[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700])[/COLOR]
[COLOR= #0000BB]$error[/COLOR][COLOR= #007700]=[/COLOR][COLOR= #DD0000]"Je moet een bericht maken!"[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/elseif"]elseif[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]naam[/COLOR][COLOR= #007700]] ==[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700])[/COLOR]
[COLOR= #0000BB]$error[/COLOR][COLOR= #007700]=[/COLOR][COLOR= #DD0000]"Je moet je naam invullen!"[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/elseif"]elseif[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]emailadres[/COLOR][COLOR= #007700]] ==[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700])[/COLOR]
[COLOR= #0000BB]$error[/COLOR][COLOR= #007700]=[/COLOR][COLOR= #DD0000]"Je moet je e-mailadres invullen!"[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/elseif"]elseif[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]onderwerp[/COLOR][COLOR= #007700]] ==[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700])[/COLOR]
[COLOR= #0000BB]$error[/COLOR][COLOR= #007700]=[/COLOR][COLOR= #DD0000]"Je moet een onderwerp invullen!"[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$error[/COLOR][COLOR= #007700])
{[/COLOR] [COLOR= #FF8000]//geen error? query opstellen[/COLOR]
[COLOR= #0000BB]$query[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"INSERT INTO nieuws (datum,bericht,emailadres,
onderwerp,naam) VALUES ($datum,$bericht,$emailadres,
$onderwerp,$naam)"[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #FF8000]//query toepassen [/COLOR]
[URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Het nieuws is toegevoegd!"[/COLOR][COLOR= #007700];
}[/COLOR]
[URL="http://www.php.net/elseif"]elseif[/URL] [COLOR= #007700](![/COLOR][COLOR= #0000BB]$error[/COLOR][COLOR= #007700])
{[/COLOR] [COLOR= #FF8000]//error kun je terug naar vorige pagina[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"
<div align="center"><table width="50%" border="1"
cellspacing="0" cellpadding="2">
<tr bordercolor="#000000">
<td bordercolor="#000000" bgcolor="#e2e2e2" height="36">
<div align="center"><div align=center>$error<br>
<form method="post" action="javascript:history.go(-1)">
<div align=center><input type="submit"
name="Terug" value="Terug">
</form></td></tr></table>"[/COLOR][COLOR= #007700];
}
}[/COLOR]
[URL="http://www.php.net/else"]else[/URL]
[COLOR= #007700]{[/COLOR] [COLOR= #FF8000]//als er nog niet op de submit knop is gedrukt dan laten we het formulier zien [/COLOR]
?> nieuws toevoegen
<u>Nieuws toevoegen: </u>
<form action="" method="post">
<table width="95%" border="0" cellspacing="0" cellpadding="0">
<tr><td>
Je naam :
</td></tr><tr><td>
<input type="text" name="naam">
</td></tr><tr><td>
Je e-mailadres :
</td></tr><tr><td>
<input type="text" name="emailadres">
</td></tr><tr><td>
Het onderwerp:
</td></tr><tr> <td>
<input type="text" name="onderwerp">
</td></tr><tr><td>
Bericht:
</td></tr><tr><td>
<textarea name="bericht" cols="60" rows="20" wrap="VIRTUAL"></textarea>
<br>
</td></tr><tr><td>
<input type="submit" value="Nieuws toevoegen" name="submit">
<input type="reset" value="Wis velden" name="reset">
</td></tr></table>
</form> Nu kan je dus berichten toevoegen in de database maar we moeten de berichten kunnen zien.
gebruik de functie SELECT
maak: Nieuws.php
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #FF8000]//Eerst connecten we[/COLOR]
[URL="http://www.php.net/mysql_connect"]mysql_connect[/URL] [COLOR= #007700]([/COLOR][COLOR= #DD0000]"....."[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]"....."[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"....."[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//host, username, password [/COLOR]
[URL="http://www.php.net/mysql_select_db"]mysql_select_db[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"nieuwssysteem"[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//database [/COLOR]
[COLOR= #0000BB]$query[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM nieuws ORDER BY id DESC"[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #FF8000]//Alles rangschikken vhnl vb: (100,99,95,94,...) [/COLOR]
[URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$obj[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_object"]mysql_fetch_object[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR][COLOR= #007700]))
{[/COLOR] [COLOR= #FF8000]//een loop creëren zodat we later de resulaten kunnen laten echöen [/COLOR]
[COLOR= #0000BB]$nieuwsid[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$obj[/COLOR][COLOR= #007700]->[/COLOR]id[COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$bericht[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/stripslashes"]stripslashes[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$obj[/COLOR][COLOR= #007700]->[/COLOR]bericht[COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//de slashes die te veel zijn weghalen[/COLOR]
[COLOR= #0000BB]$bericht[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/nl2br"]nl2br[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$bericht[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//een nieuwe lijn beginnen als er in de kolom bericht ook een nieuwe lijn begint
//Comments[/COLOR]
[COLOR= #0000BB]$rij[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM nieuwscomments WHERE nieuwsid=$nieuwsid "[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #FF8000]//comments met zelfde id als nieuwsbericht[/COLOR]
[COLOR= #0000BB]$comments[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$rij[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//aantal resultaten [/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$comments[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700])[/COLOR] [COLOR= #FF8000]//als het aantal comments gelijk is aan 1 dan gebruiken we X comment en niet X comments [/COLOR]
[COLOR= #0000BB]$commentsnaam[/COLOR] [COLOR= #007700]=[/COLOR][COLOR= #DD0000]"<a href="nieuwscomments.php?nieuwsid=$nieuwsid">$comments comment</a>"[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/elseif"]elseif[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$comments[/COLOR] [COLOR= #007700]>[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700])[/COLOR] [COLOR= #FF8000]//als het aantal comments meer is dan 1 gebruiken we X comments en niet X comment, staat niet zo mooi[/COLOR]
[COLOR= #0000BB]$commentsnaam[/COLOR] [COLOR= #007700]=[/COLOR][COLOR= #DD0000]"<a href="nieuwscomments.php?nieuwsid=$nieuwsid">$comments comments</a>"[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$comments[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]"0"[/COLOR][COLOR= #007700])[/COLOR] [COLOR= #FF8000]//als er geen comments zijn dan link naar een pagina waar je een comment kan posten [/COLOR]
[COLOR= #0000BB]$commentsnaam[/COLOR] [COLOR= #007700]=[/COLOR][COLOR= #DD0000]"<a href="postcomment.php?nieuwsid=$nieuwsid">Post comment</a>"[/COLOR][COLOR= #007700];[/COLOR]
?> <table width="98%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td height="21">
<div align="left">
[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]"$obj->datum"[/COLOR][COLOR= #007700];[/COLOR] ?>
Gepost door
[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]"$obj->naam"[/COLOR][COLOR= #007700];[/COLOR] ?>
</div>
</td></tr><tr>
<td valign="top" height="43">
<table width="100%" border="0" cellspacing="0" cellpadding="3" height="35">
<tr>
<td valign="top" height="19">
<div align="left">
[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]"$bericht"[/COLOR][COLOR= #007700];[/COLOR] ?>
</div>
</td></tr><tr>
<td valign="top" height="8">
<div align="right">[
[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]"$commentsnaam"[/COLOR][COLOR= #007700];[/COLOR] ?>
]</div>
</td></tr></table></td></tr></table>
<br>
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #007700]}[/COLOR] [COLOR= #FF8000]//de loop eindigen en herhalen tot dat hij alle records heeft geprint. [/COLOR]
?> Wat we nu nog missen is de pagina waar je reacties met kan toevoegen en een pagina waar je de comments kunt lezen.
Het probleem dat sommige mensen hebben is dat ze niet weten hoe je de comments kunt laten selecteren bij het juiste nieuwsbericht.
Wel, we maken dus een kolom bij de tabel nieuwscomments met de naam nieuwsid
Als we dan een comments toevoegen kan je het id van het nieuwsbericht in die kolom opslagen en kan je zo het de comments selecteren bij het gepaste nieuwsbericht.
Nu gaan we verder met de pagina.
postcomment.php
[COLOR= #0000BB]<?php
$datum[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/date"]date[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"d/m/Y"[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//de datum [/COLOR]
[COLOR= #0000BB]$tijd[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/date"]date[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"H:i"[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//de tijd [/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]Submit[/COLOR][COLOR= #007700]])
{[/COLOR] [COLOR= #FF8000]//als er op submit is gedrukt gaan we checken of alle velden wel zijn ingevuld ... [/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]$bericht[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700])[/COLOR]
[COLOR= #0000BB]$error[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"Je moet een bericht invullen<br><br>"[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/elseif"]elseif[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]$naam[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700])[/COLOR]
[COLOR= #0000BB]$error[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"Je moet je naam invullen<br><br>"[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/elseif"]elseif[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]$emailadres[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700])[/COLOR]
[COLOR= #0000BB]$error[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"Je moet je e-mailadres invullen<br><br>"[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700](![/COLOR][COLOR= #0000BB]$error[/COLOR][COLOR= #007700])
{[/COLOR] [COLOR= #FF8000]//als er geen error is [/COLOR]
[COLOR= #0000BB]$query[/COLOR] [COLOR= #007700]=[/COLOR][COLOR= #DD0000]"INSERT INTO nieuwscomments (naam, tijd, datum, bericht,
nieuwsid, emailadres) VALUES ($naam, $tijd, $datum, $berichtr,
$nieuwsid, $emailadres)"[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR]
[URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"location:nieuwscomments.php?nieuwsid=$nieuwsid"[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #FF8000]//als je de comment hebt gepost stuur je de bezoeker terug naar het nieuwsbericht [/COLOR]
[COLOR= #007700]}[/COLOR]
[URL="http://www.php.net/else"]else[/URL] [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$error[/COLOR][COLOR= #007700])
{[/COLOR] [COLOR= #FF8000]//als er een error is [/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"
<div align="center"><table width="50%" border="1"
cellspacing="0" cellpadding="2">
<tr bordercolor="#000000">
<td bordercolor="#000000" bgcolor="#e2e2e2" height="36">
$error<br>
<form method="post" action="javascript:history.go(-1)">
<input type="submit" name="Terug" value="Terug">
</form>
</td></tr></table></div>"[/COLOR][COLOR= #007700];
}
}[/COLOR]
[URL="http://www.php.net/else"]else[/URL]
[COLOR= #007700]{[/COLOR]
?> <form method="post" action="">
<table width="98%" border="1" cellpadding="2" cellspacing="0">
<tr>
<td height="38">
Post een reactie:<br>
<hr noshade>
Bericht:
</td></tr>
<tr><td>
<textarea name="bericht" cols="60" rows="10"></textarea>
</td></tr>
<tr><td>
<div align="left">
<input type="submit" name="Submit" value="Post comment">
<input type="reset" name="Reset" value="Wis velden">
<input type="button" value="Terug naar nieuws"
onClick="window.location=nieuwscomments.php?nieuwsid=
[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]"$nieuwsid"[/COLOR][COLOR= #007700];[/COLOR] ?>
" name="button">
</div></td></tr></table>
</form>
[COLOR= #0000BB]<?php[/COLOR] [COLOR= #007700]}[/COLOR] ?> Het laatste (
nieuwscomments.php
[COLOR= #0000BB]<?php
$obj[/COLOR][COLOR= #007700]=[/COLOR][URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM nieuws where id=$nieuwsid"[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR] [COLOR= #FF8000]//het nieuwsbericht selecteren [/COLOR]
[URL="http://www.php.net/while"]while[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$result[/COLOR][COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_object"]mysql_fetch_object[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$obj[/COLOR][COLOR= #007700]))
{[/COLOR]
[COLOR= #0000BB]$naam[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$result[/COLOR][COLOR= #007700]->[/COLOR]naam[COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$datum[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$result[/COLOR][COLOR= #007700]->[/COLOR]datum[COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$emailadres[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$result[/COLOR][COLOR= #007700]->[/COLOR]emailadres[COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$onderwerp[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/stripslashes"]stripslashes[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$result[/COLOR][COLOR= #007700]->[/COLOR]onderwerp[COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$bericht[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/stripslashes"]stripslashes[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$result[/COLOR][COLOR= #007700]->[/COLOR]bericht[COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$bericht[/COLOR] [COLOR= #007700]=[/COLOR][URL="http://www.php.net/nl2br"]nl2br[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$bericht[/COLOR][COLOR= #007700]);
}[/COLOR]
?>
<table width="98%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td height="21">
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"$datum "[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Gepost door: <a href="mailto: $emailadres">$naam</a> "[/COLOR][COLOR= #007700]);[/COLOR]
?>
</td>
</tr><tr>
<td valign="top" height="24">
<table width="100%" border="0" cellspacing="0" cellpadding="3" height="35">
<tr>
<td valign="top" height="12">
[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]"$bericht"[/COLOR][COLOR= #007700];[/COLOR] ?>
</td></tr></table>
</td></tr></table>
<br>
[COLOR= #0000BB]<?php
$rij[/COLOR][COLOR= #007700]=[/COLOR][URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM nieuwscomments where nieuwsid=$nieuwsid"[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR]
[COLOR= #FF8000]//comments met zelfde id als nieuwssysteem[/COLOR]
[URL="http://www.php.net/while"]while[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$result[/COLOR][COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_object"]mysql_fetch_object[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$rij[/COLOR][COLOR= #007700]))
{[/COLOR] [COLOR= #FF8000]//een loop maken [/COLOR]
[COLOR= #0000BB]$aantal[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$rij[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$naam2[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$result[/COLOR][COLOR= #007700]->[/COLOR]naam[COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$datum2[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$result[/COLOR][COLOR= #007700]->[/COLOR]datum[COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$tijd2[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$result[/COLOR][COLOR= #007700]->[/COLOR]tijd[COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$emailadres2[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$result[/COLOR][COLOR= #007700]->[/COLOR]emailadres[COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$bericht2[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/stripslashes"]stripslashes[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$result[/COLOR][COLOR= #007700]->[/COLOR]bericht[COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$bericht2[/COLOR][COLOR= #007700]=[/COLOR] [URL="http://www.php.net/nl2br"]nl2br[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$bericht2[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$aantal[/COLOR] [COLOR= #007700]>[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700])
{[/COLOR] [COLOR= #FF8000]//alleen als er nieuws is[/COLOR]
?>
<table width="98%" border="1" cellspacing="0" cellpadding="2">
<tr>
<td valign="top" height="43"> Gepost door :
[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"$datum2 $tijd2"[/COLOR][COLOR= #007700]);[/COLOR] ?>
<br>
<hr noshade>
[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"$bericht2"[/COLOR][COLOR= #007700]);[/COLOR] ?>
</td>
</tr>
</table>
<br>
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #007700]}
}[/COLOR] [COLOR= #FF8000]//de loop eindigen en herhalen tot dat hij alle records heeft geprint. [/COLOR]
?>
<input type="submit" name="Submit2" value="Terug naar nieuws" onclick="window.location=index.php">
<input type="submit" name="Submit" value="Post een comment"
onclick="window.location=
[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]"postcomment.php?nieuwsid=$nieuwsid"[/COLOR][COLOR= #007700];[/COLOR] ?>
"> Het nieuwssysteem is eindelijk af
Je kan eventueel nog een admin pagina maken met verwijder en wijzig functie en er een loginsysteem op zetten maar mag je lekkur zelf doen
.Succes, wijziging/fout? laat het even weten!

33:
$naam etc. moeten niet tussen " en " bij echo 
