Undefined index

Gestart doorJob7 reacties60 weergaven

8 berichten · pagina 1 van 1

Job

Lid · Topicstarter

Berichten
425
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hallo allemaal,
Ik heb net een scriptje van het internet geplukt om wat mee te klooien om wat beter in PHP te worden (vandaar dat je wel wat vragen van me de komende tijd kunt verwachten), en ik kom de Undefined index error tegen. Hieronder de code.

<body>

[COLOR= #0000BB]<?[/COLOR]

[URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"connect.php"[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"functions.php"[/COLOR][COLOR= #007700]);[/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= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]na_am[/COLOR][COLOR= #007700]] &&[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]beri_cht[/COLOR][COLOR= #007700]] &&[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]tit_el[/COLOR][COLOR= #007700]])
{[/COLOR] 
[COLOR= #0000BB]$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= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]beri_cht[/COLOR][COLOR= #007700]] =[/COLOR] filter[COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]beri_cht[/COLOR][COLOR= #007700]]);[/COLOR]

[COLOR= #0000BB]$sql[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"INSERT INTO topics SET id = , titel = "[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]tit_el[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000]", bericht = "[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]beri_cht[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000]", datum = "[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$datum[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]", naam = "[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]na_am[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$res[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700]);[/COLOR]

    [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$res[/COLOR][COLOR= #007700]) 
    {[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Topic toegevoegd! Ga naar het <a href="topics.php">topic overzicht</a>"[/COLOR][COLOR= #007700];
    }[/COLOR]
    [URL="http://www.php.net/else"]else[/URL]
    [COLOR= #007700]{[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Topic <b>niet</b> toegevoegd! Probeer het <a href=""[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$PHP_SELF[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]"">opnieuw</a>"[/COLOR][COLOR= #007700];
    }
}[/COLOR]   
[URL="http://www.php.net/elseif"]elseif[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]submit[/COLOR][COLOR= #007700]] ||[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]na_am[/COLOR][COLOR= #007700]] ||[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]beri_cht[/COLOR][COLOR= #007700]] ||[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]tit_el[/COLOR][COLOR= #007700]])
{[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Niet alle velden ingevult! Probeer het <a href=""[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$PHP_SELF[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]"">opnieuw</a>"[/COLOR][COLOR= #007700];
}[/COLOR]
[URL="http://www.php.net/else"]else[/URL]
[COLOR= #007700]{[/COLOR]
    
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<center>"[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<table border="0" cellspacing="0" cellpadding="5" align="center">"[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<form method="POST" action=""[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$PHP_SELF[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]"">"[/COLOR][COLOR= #007700];[/COLOR]

   
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<tr><td>Je naam:*</td></tr>"[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<tr><td><input type="text" name="na_am"></td></tr>"[/COLOR][COLOR= #007700];[/COLOR]

    
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<tr><td> </td></tr>"[/COLOR][COLOR= #007700];[/COLOR]
    
    
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<tr><td>Titel:*</td></tr>"[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<tr><td><input type="text" name="tit_el"></td></tr>"[/COLOR][COLOR= #007700];[/COLOR]

    
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<tr><td> </td></tr>"[/COLOR][COLOR= #007700];[/COLOR]

    
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<tr><td>Bericht:*</td></tr>"[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<tr><td><textarea name="beri_cht" rows="5" cols="15"></textarea></td></tr>"[/COLOR][COLOR= #007700];[/COLOR]

    
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<tr><td>Alle velden zijn verplicht! </td></tr>"[/COLOR][COLOR= #007700];[/COLOR]

    
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<tr><td><input type="submit" name="submit" value="Plaats!" class="buttons">&nbsp<input type="reset" value="Wis" class="buttons"></td></tr>"[/COLOR][COLOR= #007700];[/COLOR]
    
    
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"</form>"[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"</table>"[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"</center>"[/COLOR][COLOR= #007700];
}[/COLOR]

?>
</body>
</html>


En hieronder de ERROR.
Notice: Undefined index: submit in C:xampphtdocsForumaddtopic.php on line 15

Notice: Undefined index: submit in C:xampphtdocsForumaddtopic.php on line 32

Notice: Undefined index: na_am in C:xampphtdocsForumaddtopic.php on line 32

Notice: Undefined index: beri_cht in C:xampphtdocsForumaddtopic.php on line 32

Notice: Undefined index: tit_el in C:xampphtdocsForumaddtopic.php on line 32

Notice: Undefined variable: PHP_SELF in C:xampphtdocsForumaddtopic.php on line 41


Kan iemand mij vertellen wat hier fout gaat en hoe ik dit in de toekomst op kan lossen?
0
Berichten
35.796
Reputatie
1
Punten
0,00
Lid sinds
Laatst gezien
Plaats dan even het hele script of corrigeer ook de foutmledingen; de foutmeldingen zoals die hier staan kunnen niet van dit script hierboven zijn.

toevoeging op 15 juni 2013, 201434:
Al raad ik je aan een ander script te zoeken om mee te oefenen, dit is pure bagger waar je enkel slechte dingen van leert.
0
Job

Lid · Topicstarter

Berichten
425
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Meh, heb je misschien een link naar een niet té ingewikkeld PHP systeempje waar ik mee kan oefenen? Op Google kom ik vaker dit soort systemen tegen met foutmeldingen namelijk.
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
- De fout komt er op neer dat je $_POST[tit_el] etc... niet bestaat
Gelieve dus even met if($_SERVER[REQUEST_METHOD]=="POST") { te controelren of deze bestaan.
- Tevens in SQL-injection mogelijk > Gevaarlijk!!!!
- $_PHP_SELF is al lang ter ziele. Het is nu een onderdeel van de $_SERVER global: $_SERVER[PHP_SELF], maar dit hoef je niet eens in een formulier te gebruiken, geen meerwaarde. Als je hem leeg laat is het ook prima.
0
Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Je bent alle isset(); vergeten op lijn8

toevoeging op 15 juni 2013, 21:51:28:
Wat aarclay zegt kan ook.
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Ik doe het eigenlijk altijd standaard smile
empty() raad ik wel altijd af voor formulier-controles. Deze staan meer niet toe dan je denkt... wink
0
Job

Lid · Topicstarter

Berichten
425
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Dankjullie wel. Ik zal eens eventjes zoeken naar een goed script waar ik wel mee kan oefenen smile. Nogmaals dank!
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