php tut met get , variable , echo & post

Gestart doorSmiegles19 reacties188 weergaven

20 berichten · pagina 1 van 2

Smiegles

Lid · Topicstarter

Berichten
4.912
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien

welkom op mijn Php tut.

inleiding
1 .) echo
2 .) variable
3 .) get
4 .) post
5 .) array

1.) waarom werkt niet?

Dat komt omdat er een echo ; tussen moet.
hoe dat werkt?
heel makkelijk!

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Hier de tekst[/COLOR][COLOR= #007700];[/COLOR]
?>


en wat is hier het verschil dan?

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"hoi"[/COLOR][COLOR= #007700];[/COLOR]
?>


Nu nog niks maar als je bijvoorbeeld een div in een echo wil zitten kan je niet 2 x ""
voorbeeld

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<div id="voorbeeld">div</div>[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]// Kan wel[/COLOR]
?>


en

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<div id="[/COLOR]voorbeeld[COLOR= #DD0000]">div</div>"[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]// Kan Niet[/COLOR]
?>


dat is dus omdat je geen 2 dubbele " kan hebben

2.) $Variable = hoi; en ik zie geen hoi?

Jha dat klopt
een variable is namelijk een stukje script die zegt "Dit betekent dit"
dus

[COLOR= #0000BB]<?php
$dit[/COLOR] [COLOR= #007700]=[/COLOR] dat[COLOR= #007700];[/COLOR]
?>


en zegt dus nog niks.
daarvoor gebruiken we de echo functie.

[COLOR= #0000BB]<?php
$dit[/COLOR] [COLOR= #007700]=[/COLOR] dat[COLOR= #007700];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$dit[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]// output = dat[/COLOR]
?>


bij het ophalen van alleen een variable hoef je geen "" of te gebruiken maar wel een ;
LET OP!
dit kan wel

[COLOR= #0000BB]<?php
$dit[/COLOR] [COLOR= #007700]=[/COLOR] dat[COLOR= #007700];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$dit[/COLOR][COLOR= #007700];[/COLOR]
?>


Dit kan niet

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$dit[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$dit[/COLOR] [COLOR= #007700]=[/COLOR] dat[COLOR= #007700];[/COLOR]
?>


dat komt omdat $dit dan nog niet bestaat
3.) de get

Get betekent eigelijk gewoon krijgen.
de functie van de get is om iets uit de url te krijgen.
de url is de link van een website
voorbeeld
www.site.nl/index.php?get=welkom
wij wullen nu uit de get welkom krijgen.
dat doen we met de echo uit stap 1.

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]get[/COLOR][COLOR= #007700]];[/COLOR]
?>


of wat ook kan

[COLOR= #0000BB]<?php
$get[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]get[/COLOR][COLOR= #007700]];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$get[/COLOR][COLOR= #007700];[/COLOR]
?>


nu zou bij de url
Quote:
www.site.nl/index.php?get=welkom

welkom op de pagina staan.
maar als je dit in de url hebt

Quote:
www.site.nl/index.php?get=welbr />kom

zou dit in de pagina staan

Quote:
wel
kom


dat willen we niet.
dus daarvoor gebruiken we htmlentities
die zetten we als het waren om de get heen.
dus bijvoorbeeld.

[COLOR= #0000BB]<?php
$get[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]get[/COLOR][COLOR= #007700]];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] htmlentities[COLOR= #007700]([/COLOR][COLOR= #0000BB]$get[/COLOR][COLOR= #007700]);[/COLOR]
?>


nu zou bij

Quote:
www.site.nl/index.php?get=welbr />kom

de output

Quote:
welbr />kom

zijn !

4.) posten! (welkom maar wie ben jij?)

daar gaan we deze functies voor gebruiken.
echo
isset
if
else
$_POST

we beginnen met een Simpele form

<form action="" method="post">
Wat is jou naam? :<input type="text" name="naam"><br>
<input type="submit" value="Verzenden">
</form>


nu gaan we eerst kijken of er al iets verzonden is.
dat doen we met de functie isset,post & if

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_post[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]verzenden[/COLOR][COLOR= #007700]])) {[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]naam[/COLOR][COLOR= #007700]];
}[/COLOR]
?>
<form action="" method="post">
Wat is jou naam? :<input type="text" name="naam"><br>
<input type="submit" value="Verzenden">
</form>


Maar als de post is verzonden hoe zorg ik ervoor dat die post balk dan weg is?
daar gebruken we else voor
dat ziet er zo uit

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]verzenden[/COLOR][COLOR= #007700]])) { <[/COLOR] beginnen met een [COLOR= #007700]{ ----[/COLOR] 
[COLOR= #FF8000]// wat als er iets verzonden is?[/COLOR]
[COLOR= #007700]}[/COLOR] [COLOR= #FF8000]// << afsluiten met een }[/COLOR]
[URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
[COLOR= #FF8000]// wat als er niets verzonden is?[/COLOR]
[COLOR= #007700]}[/COLOR]
?>


dus

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_post[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]verzenden[/COLOR][COLOR= #007700]])) {[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]naam[/COLOR][COLOR= #007700]];
}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
?>
<form action="" method="post">
Wat is jou naam? :<input type="text" name="naam"><br>
<input type="submit" name="verzenden" value="Verzenden">
</form>
[COLOR= #0000BB]<?php[/COLOR] [COLOR= #007700]}[/COLOR] ?>


5 .) alles op een reitje

een array is een simpel lijstje die je maakt op dingen een waarde tegeven

bijvoorbeeld.

1 = admin
2 = moderator
3 = lid
4 = verbannen

Dit gaan we nu maken.

[COLOR= #0000BB]<?php
$array[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #FF8000]// we beginnen met een variable om een waarde tegeven aan 1,2,3,4[/COLOR]
?>


Nu gaan we de array starten en stoppen

[COLOR= #0000BB]<?php
$array[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL] [COLOR= #007700](

                );[/COLOR]
?>


zoals je ziet staat er nu dat array niks waard is omdat er Niks instaat dat gaan we nu doen.

[COLOR= #0000BB]<?php
$array[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL] [COLOR= #007700]([/COLOR]
        [COLOR= #0000BB]1[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700],[/COLOR]
        [COLOR= #0000BB]2[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700],[/COLOR]
        [COLOR= #0000BB]3[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700],[/COLOR]
        [COLOR= #0000BB]4[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000][/COLOR]
                [COLOR= #007700]);[/COLOR]
?>


Nu moeten alle getallen een waarde
dat doen we zo

[COLOR= #0000BB]<?php
$array[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL] [COLOR= #007700]([/COLOR]
        [COLOR= #0000BB]1[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000]admin[/COLOR][COLOR= #007700],[/COLOR]
        [COLOR= #0000BB]2[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000]moderator[/COLOR][COLOR= #007700],[/COLOR]
        [COLOR= #0000BB]3[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000]lid[/COLOR][COLOR= #007700],[/COLOR]
        [COLOR= #0000BB]4[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000]verbannen[/COLOR]
                [COLOR= #007700]);[/COLOR]
?>


Nu hebben alle getallen een waarde en zijn ze klaar voor gebruik.

[COLOR= #0000BB]<?php
$array[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL] [COLOR= #007700]([/COLOR]
        [COLOR= #0000BB]1[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000]admin[/COLOR][COLOR= #007700],[/COLOR]
        [COLOR= #0000BB]2[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000]moderator[/COLOR][COLOR= #007700],[/COLOR]
        [COLOR= #0000BB]3[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000]lid[/COLOR][COLOR= #007700],[/COLOR]
        [COLOR= #0000BB]4[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000]verbannen[/COLOR]
                [COLOR= #007700]);[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$array[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]1[/COLOR][COLOR= #007700]];[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<br />[/COLOR][COLOR= #007700];[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$array[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]2[/COLOR][COLOR= #007700]];[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<br />[/COLOR][COLOR= #007700];[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$array[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]3[/COLOR][COLOR= #007700]];[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<br />[/COLOR][COLOR= #007700];[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$array[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]4[/COLOR][COLOR= #007700]];[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<br />[/COLOR][COLOR= #007700];[/COLOR]
?>


Later Nog meeer
// eind php tut
?>
0
Berichten
139
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Nice tut, heb er wat vaan geleerd!
0
Smiegles

Lid · Topicstarter

Berichten
4.912
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Dexter schreef:
Nice tut, heb er wat vaan geleerd!
Tof dankjebiggrinzal zo meteen een array tut toevoegen
0
Berichten
6.037
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
bij het tweede code venster. sluit je je echo af met : ?
0
Smiegles

Lid · Topicstarter

Berichten
4.912
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Jordyvc schreef:
bij het tweede code venster. sluit je je echo af met : ?
bedankt aangepastbloos
0
Berichten
6.037
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Het is wel een goede tut, heb er al veel van geleerd.
alleen snap ik iets niet code venster 15 dat Post.
ik heb dat script op mijn host geplaatst.
http://www.jordyvc.s3.one2xs.com/php.php
Als ik daar mijn naam intyp komt er niets?
of is dat de bedoeling?
0
Berichten
7.681
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Wel leuk alleen de array tut is veel te simpel neer gezet. En veel te incompleet.
0
Berichten
13.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Jordyvc schreef:
Het is wel een goede tut, heb er al veel van geleerd.
alleen snap ik iets niet code venster 15 dat Post.
ik heb dat script op mijn host geplaatst.
http://www.jordyvc.s3.one2xs.com/php.php
Als ik daar mijn naam intyp komt er niets?
of is dat de bedoeling?
name="verzenden" is bij de input met het type "submit" weggelaten
0
Berichten
6.037
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_post[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]verzenden[/COLOR][COLOR= #007700]])){[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]naam[/COLOR][COLOR= #007700]];
}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
?>
<form action="" method="post">
 <input type="text" name="verzenden"><br>
<input type="" value="Stuur">
</form>
[COLOR= #0000BB]<?php[/COLOR] [COLOR= #007700]}[/COLOR] ?>


Dan krijg ik 2 textboxen?
0
Berichten
7.681
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Jordyvc schreef:
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_post[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]verzenden[/COLOR][COLOR= #007700]])){[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]naam[/COLOR][COLOR= #007700]];
}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
?>
<form action="" method="post">
 <input type="text" name="verzenden"><br>
<input type="" value="Stuur">
</form>
[COLOR= #0000BB]<?php[/COLOR] [COLOR= #007700]}[/COLOR] ?>
Dan krijg ik 2 textboxen?

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_post[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]verzenden[/COLOR][COLOR= #007700]])){[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]naam[/COLOR][COLOR= #007700]];
}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
?>
<form action="" method="post">
 Naam: <input type="text" name="naam"><br>
<input type="submit" name="verzenden" value="Stuur">
</form>
[COLOR= #0000BB]<?php[/COLOR] [COLOR= #007700]}[/COLOR] ?>
0
Smiegles

Lid · Topicstarter

Berichten
4.912
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ik zal zo de array tut verder uitbreiden en nog wet dingentjes uitleggen smile
0
Berichten
242
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
goede tut thumbsupAlleen wil je bij sommige dingen wat beter uit leggen wat het betekent.
Want ik denk als je niet weet wat iets betekent dat je het ook niet snapt smile
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php
$dit[/COLOR] [COLOR= #007700]=[/COLOR] dat [COLOR= #FF8000]// Faal[/COLOR]
[COLOR= #0000BB]$dit[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]dat[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]// jeuh ;d[/COLOR]
?>


dat is dus omdat je geen 2 dubbele " kan hebben


Je bedoeld denk omdat je geen " kan gebruiken in een echo die je opent met "
Dat kan wel hoor? emo
Dan doe je ervoor emo
0
Berichten
788
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ty, weer wat geleert van php biggrin
0
Smiegles

Lid · Topicstarter

Berichten
4.912
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
zal ik classes en Config uitleggen?
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren