Je bent ingelogd werkt niet

Gestart doorDylan25 reacties60 weergaven

26 berichten · pagina 2 van 2

Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Goededag schreef:
session_start() ?
Joeyl schreef:
Misschien is het al eerder gezegd, maar je kan beter een if else maken ipv een die.

Edit: Heb je wel een session_start?
Zien jullie ergens een session variable staan? Nee.
Moet er dan session_start? Nee.
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Goededag schreef:
session_start() ?
Joeyl schreef:
Misschien is het al eerder gezegd, maar je kan beter een if else maken ipv een die.

Edit: Heb je wel een session_start?
Zien jullie ergens een session variable staan? Nee.
Moet er dan session_start? Nee.
0
Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Aarclay schreef:
Nee, hiermee sla je de waardes uit je formulier op in een variabele, wat niet echt nodig is. Je hebt die waardes toch al in $_POST[username] en $_POST[password] staan? Waarom zou je ze dan nog in $username en $password plaatsen?

En bovendien zijn $_POST variabelen pas alleen beschikbaar als je gecontroleerd hebt of je formulier is verstuurd via de POST-methode. Dit doe je uitsluitend met:

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]REQUEST_METHOD[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]"POST"[/COLOR][COLOR= #007700]) {[/COLOR]
En niet anders wink.

En als je die if en else doet lost dat dan deze fout op?
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #FF8000]// session_start();[/COLOR]
[URL="http://www.php.net/mysql_connect"]mysql_connect[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"localhost"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"root"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Kan niet met de MySQL server verbinden"[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/mysql_select_db"]mysql_select_db[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"phplogin"[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"database niet gevonden"[/COLOR][COLOR= #007700]);[/COLOR]

[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]REQUEST_METHOD[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]POST[/COLOR][COLOR= #007700])
{[/COLOR]
    [COLOR= #0000BB]$arrErrors[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]();[/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]username[/COLOR][COLOR= #007700]]) &&[/COLOR] [URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]wachtwoord[/COLOR][COLOR= #007700]]))
    {[/COLOR]
        [COLOR= #0000BB]$userQuery[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM users WHERE username = "[/COLOR] [COLOR= #007700].[/COLOR] [URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]username[/COLOR][COLOR= #007700]]) .[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700]);[/COLOR]
    
        [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sQuery[/COLOR][COLOR= #007700]) ==[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700])
        {[/COLOR]
            [COLOR= #0000BB]$userFetch[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$userQuery[/COLOR][COLOR= #007700]);[/COLOR]
    
            [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$userFetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]wachtwoord[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]wachtwoord[/COLOR][COLOR= #007700]])
            {[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Je bent succesvol ingelogd[/COLOR][COLOR= #007700];[/COLOR]
                
                [COLOR= #FF8000]// Doorsturen of session stuff hier[/COLOR]
            [COLOR= #007700]}[/COLOR]
            [URL="http://www.php.net/else"]else[/URL]
            [COLOR= #007700]{[/COLOR]
                [COLOR= #0000BB]$arrErrors[/COLOR][COLOR= #007700][] =[/COLOR] [COLOR= #DD0000]Wachtwoord klopt niet.[/COLOR][COLOR= #007700];
            }
        
        }[/COLOR]
        [URL="http://www.php.net/else"]else[/URL]
        [COLOR= #007700]{[/COLOR]
            [COLOR= #0000BB]$arrErrors[/COLOR][COLOR= #007700][] =[/COLOR] [COLOR= #DD0000]Gebruikersnaam niet gevonden[/COLOR][COLOR= #007700];
        }
    }[/COLOR]
    [URL="http://www.php.net/else"]else[/URL]
    [COLOR= #007700]{[/COLOR]
        [COLOR= #0000BB]$arrErrors[/COLOR][COLOR= #007700][] =[/COLOR] [COLOR= #DD0000]Voer uw gebruikersnaam en wachtwoord in.[/COLOR][COLOR= #007700];
    }[/COLOR]
    
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Er [/COLOR] [COLOR= #007700]. ([/COLOR][URL="http://www.php.net/count"]count[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$arrErrors[/COLOR][COLOR= #007700]) ==[/COLOR] [COLOR= #0000BB]1[/COLOR] [COLOR= #007700]?[/COLOR] [COLOR= #DD0000]is 1 fout[/COLOR] [COLOR= #007700]:[/COLOR] [COLOR= #DD0000]zijn [/COLOR] [COLOR= #007700].[/COLOR] [URL="http://www.php.net/count"]count[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$arrErrors[/COLOR][COLOR= #007700]) .[/COLOR] [COLOR= #DD0000] fouten[/COLOR][COLOR= #007700]) .[/COLOR] [COLOR= #DD0000] opgetreden:<br />[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/foreach"]foreach[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$arrErrors[/COLOR] [COLOR= #007700]as[/COLOR] [COLOR= #0000BB]$errId[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #0000BB]$errMelding[/COLOR][COLOR= #007700])
    {[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$errMelding[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]<br />[/COLOR][COLOR= #007700];        
    }
}[/COLOR]

[COLOR= #FF8000]// Form hieronder[/COLOR]
?>
0
Berichten
1.631
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Zet helemaal en dan ook helemaal bovenaan je script:

0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
bovenaan in je
0
Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Rik schreef:
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #FF8000]// session_start();[/COLOR]
[URL="http://www.php.net/mysql_connect"]mysql_connect[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"localhost"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"root"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Kan niet met de MySQL server verbinden"[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/mysql_select_db"]mysql_select_db[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"phplogin"[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"database niet gevonden"[/COLOR][COLOR= #007700]);[/COLOR]

[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]REQUEST_METHOD[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]POST[/COLOR][COLOR= #007700])
{[/COLOR]
    [COLOR= #0000BB]$arrErrors[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]();[/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]username[/COLOR][COLOR= #007700]]) &&[/COLOR] [URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]wachtwoord[/COLOR][COLOR= #007700]]))
    {[/COLOR]
        [COLOR= #0000BB]$userQuery[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM users WHERE username = "[/COLOR] [COLOR= #007700].[/COLOR] [URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]username[/COLOR][COLOR= #007700]]) .[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700]);[/COLOR]
    
        [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sQuery[/COLOR][COLOR= #007700]) ==[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700])
        {[/COLOR]
            [COLOR= #0000BB]$userFetch[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$userQuery[/COLOR][COLOR= #007700]);[/COLOR]
    

            [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$userFetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]wachtwoord[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]wachtwoord[/COLOR][COLOR= #007700]])
            {[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Je bent succesvol ingelogd[/COLOR][COLOR= #007700];[/COLOR]
                
                [COLOR= #FF8000]// Doorsturen of session stuff hier[/COLOR]
            [COLOR= #007700]}[/COLOR]
            [URL="http://www.php.net/else"]else[/URL]
            [COLOR= #007700]{[/COLOR]
                [COLOR= #0000BB]$arrErrors[/COLOR][COLOR= #007700][] =[/COLOR] [COLOR= #DD0000]Wachtwoord klopt niet.[/COLOR][COLOR= #007700];
            }
        
        }[/COLOR]
        [URL="http://www.php.net/else"]else[/URL]
        [COLOR= #007700]{[/COLOR]
            [COLOR= #0000BB]$arrErrors[/COLOR][COLOR= #007700][] =[/COLOR] [COLOR= #DD0000]Gebruikersnaam niet gevonden[/COLOR][COLOR= #007700];
        }
    }[/COLOR]
    [URL="http://www.php.net/else"]else[/URL]
    [COLOR= #007700]{[/COLOR]
        [COLOR= #0000BB]$arrErrors[/COLOR][COLOR= #007700][] =[/COLOR] [COLOR= #DD0000]Voer uw gebruikersnaam en wachtwoord in.[/COLOR][COLOR= #007700];
    }[/COLOR]
    
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Er [/COLOR] [COLOR= #007700]. ([/COLOR][URL="http://www.php.net/count"]count[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$arrErrors[/COLOR][COLOR= #007700]) ==[/COLOR] [COLOR= #0000BB]1[/COLOR] [COLOR= #007700]?[/COLOR] [COLOR= #DD0000]is 1 fout[/COLOR] [COLOR= #007700]:[/COLOR] [COLOR= #DD0000]zijn [/COLOR] [COLOR= #007700].[/COLOR] [URL="http://www.php.net/count"]count[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$arrErrors[/COLOR][COLOR= #007700]) .[/COLOR] [COLOR= #DD0000] fouten[/COLOR][COLOR= #007700]) .[/COLOR] [COLOR= #DD0000] opgetreden:<br />[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/foreach"]foreach[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$arrErrors[/COLOR] [COLOR= #007700]as[/COLOR] [COLOR= #0000BB]$errId[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #0000BB]$errMelding[/COLOR][COLOR= #007700])
    {[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$errMelding[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]<br />[/COLOR][COLOR= #007700];        
    }
}[/COLOR]

[COLOR= #FF8000]// Form hieronder[/COLOR]
?>
<form action=login2.php method=POST>
    
    Gebruikersnaam: <input type=text name=username> <br />
    Wachtwoord: <input type=password name=password><br />
    <input type=submit value=Log in!>
    
    </form>
Als ik inlog krijg ik:
Er is 1 fout opgetreden:
Voer uw gebruikersnaam en wachtwoord in. Terwijl ik dat wel heb gedaan
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Kijk dan ook even welke post waardes ik gebruikt heb... Een beetje zelf moeite doen mag ook wel he. Je moet niet altijd klakkeloos dingen overnemen.

Ik wist bijvoorbeeld niet welke form-namen je gebruikt had, dus heb ik maar username en wachtwoord genomen.
0
Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Notice: Undefined index: wachtwoord in C:xampphtdocsuploadlogin2.php on line 16
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Dylanh schreef:
Notice: Undefined index: wachtwoord in C:xampphtdocsuploadlogin2.php on line 16
Lees het bericht boven je nou eens?
0
Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Het is al opgelost
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