PHP login systeem faalt

Gestart doorVermeerenn3 reacties18 weergaven

4 berichten · pagina 1 van 1

Vermeerenn

Lid · Topicstarter

Berichten
12
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Geeft de boodschap "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/nielsfy47/domains/mini-laptop-aanbiedingen.nl/public_html/checklogin.php" weer. Wat is er fout? Ik snap het maar niet

[COLOR= #0000BB]<?php
$gebruikersnaam[/COLOR][COLOR= #007700]=[/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]];[/COLOR]
[COLOR= #0000BB]$wachtwoord[/COLOR][COLOR= #007700]=[/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]wachtwoord[/COLOR][COLOR= #007700]];[/COLOR]


[COLOR= #FF8000]// To protect MySQL injection (more detail about MySQL injection)[/COLOR]
 [COLOR= #0000BB]$gebruikersnaam[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/stripslashes"]stripslashes[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$gebruikersnaam[/COLOR][COLOR= #007700]);[/COLOR]
 [COLOR= #0000BB]$wachtwoord[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/stripslashes"]stripslashes[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$wachtwoord[/COLOR][COLOR= #007700]);[/COLOR]

     [URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]connectmysql.php[/COLOR][COLOR= #007700]);[/COLOR]
     [URL="http://www.php.net/MYSQL_SELECT_DB"]MYSQL_SELECT_DB[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]nieuwsbrief[/COLOR][COLOR= #007700]);[/COLOR]
     [COLOR= #0000BB]$sql[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"SELECT wachtwoord FROM nielsfy47_mla WHERE gebruikersnaam=$gebruikersnaam AND wachtwoord=$wachtwoord OR DIE mysql_error();"[/COLOR][COLOR= #007700];[/COLOR]
     [COLOR= #0000BB]$result[/COLOR][COLOR= #007700]=[/COLOR] [URL="http://www.php.net/MYSQL_QUERY"]MYSQL_QUERY[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700]);[/COLOR]
    [COLOR= #0000BB]$count[/COLOR][COLOR= #007700]=[/COLOR][URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$result[/COLOR][COLOR= #007700]);[/COLOR]
    
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$count[/COLOR][COLOR= #007700]==[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700]){[/COLOR]

 [URL="http://www.php.net/session_register"]session_register[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"gebruikersnaam"[/COLOR][COLOR= #007700]);[/COLOR]
 [URL="http://www.php.net/session_register"]session_register[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"wachtwoord"[/COLOR][COLOR= #007700]);[/COLOR] 
 [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"location:login_success.php"[/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]"Verkeerde gebruikersnaam of wachtwoord"[/COLOR][COLOR= #007700];
 }[/COLOR]
 ?>
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Regel 14 vervangen in:
$count=mysql_num_rows($sql);
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Xjessex schreef:
Regel 14 vervangen in:
$count=mysql_num_rows($sql);
Dat werkt helemaal niet emo
Je hele mysql gedoe klopte gewoon voor geen meter. Functies moeten lowercase, en je query klopte al niet, dus als je dan gaat kijken of er rows zijn dan krijg je daar uiteraard een fout.

[COLOR= #0000BB]<?php[/COLOR]
    [URL="http://www.php.net/mysql_select_db"]mysql_select_db[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]nieuwsbrief[/COLOR][COLOR= #007700]);[/COLOR]
    [COLOR= #0000BB]$sql[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"SELECT wachtwoord FROM nielsfy47_mla WHERE gebruikersnaam="[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$gebruikersnaam[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]" AND wachtwoord="[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$wachtwoord[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700];[/COLOR]
    [COLOR= #0000BB]$result[/COLOR][COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/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]

?>


Bovendien zijn alle session_* functies sinds 5.3.0 deprecated (verouderd). Je kan beter zoiets doen:

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

    [URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]connectmysql.php[/COLOR][COLOR= #007700]);[/COLOR]

    [COLOR= #FF8000]// To protect MySQL injection (more detail about MySQL injection)[/COLOR]
     [COLOR= #0000BB]$gebruikersnaam[/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]gebruikersnaam[/COLOR][COLOR= #007700]]);[/COLOR]
     [COLOR= #0000BB]$wachtwoord[/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]wachtwoord[/COLOR][COLOR= #007700]]);[/COLOR]
    
    [URL="http://www.php.net/mysql_select_db"]mysql_select_db[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]nieuwsbrief[/COLOR][COLOR= #007700]);[/COLOR]
     
    [COLOR= #0000BB]$sql[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"SELECT wachtwoord FROM nielsfy47_mla WHERE gebruikersnaam="[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$gebruikersnaam[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]" AND wachtwoord="[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$wachtwoord[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700];[/COLOR]
    [COLOR= #0000BB]$result[/COLOR][COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/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= #0000BB]$sRowCount[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sResult[/COLOR][COLOR= #007700]);[/COLOR]
    
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sRowCount[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700])
    {[/COLOR]
        [COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"gebruikersnaam"[/COLOR][COLOR= #007700]] =[/COLOR] [COLOR= #0000BB]$gebruikersnaam[/COLOR][COLOR= #007700];[/COLOR] 
         [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"LOCATION: login_success.php"[/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]"Verkeerde gebruikersnaam of wachtwoord"[/COLOR][COLOR= #007700];
     }[/COLOR]
    
 ?>


Zie ook dat ik wachtwoord in session weg heb gehaald. Het opslaan van wachtwoorden in cookies of sessions is echt een big NO-GO.
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Rik schreef:
Eerdere citaten tonen
Xjessex schreef:
Regel 14 vervangen in:
$count=mysql_num_rows($sql);

Dat werkt helemaal niet emo
Je hele mysql gedoe klopte gewoon voor geen meter. Functies moeten lowercase, en je query klopte al niet, dus als je dan gaat kijken of er rows zijn dan krijg je daar uiteraard een fout.

[COLOR= #0000BB]<?php[/COLOR]
    [URL="http://www.php.net/mysql_select_db"]mysql_select_db[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]nieuwsbrief[/COLOR][COLOR= #007700]);[/COLOR]
    [COLOR= #0000BB]$sql[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"SELECT wachtwoord FROM nielsfy47_mla WHERE gebruikersnaam="[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$gebruikersnaam[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]" AND wachtwoord="[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$wachtwoord[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700];[/COLOR]
    [COLOR= #0000BB]$result[/COLOR][COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/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]

?>


Bovendien zijn alle session_* functies sinds 5.3.0 deprecated (verouderd). Je kan beter zoiets doen:

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

    [URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]connectmysql.php[/COLOR][COLOR= #007700]);[/COLOR]

    [COLOR= #FF8000]// To protect MySQL injection (more detail about MySQL injection)[/COLOR]
     [COLOR= #0000BB]$gebruikersnaam[/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]gebruikersnaam[/COLOR][COLOR= #007700]]);[/COLOR]
     [COLOR= #0000BB]$wachtwoord[/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]wachtwoord[/COLOR][COLOR= #007700]]);[/COLOR]
    
    [URL="http://www.php.net/mysql_select_db"]mysql_select_db[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]nieuwsbrief[/COLOR][COLOR= #007700]);[/COLOR]
     
    [COLOR= #0000BB]$sQuery[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"SELECT wachtwoord FROM nielsfy47_mla WHERE gebruikersnaam=$gebruikersnaam AND wachtwoord=$wachtwoord OR DIE mysql_error();"[/COLOR][COLOR= #007700];[/COLOR]
    [COLOR= #0000BB]$sResult[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sQuery[/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= #0000BB]$sRowCount[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sResult[/COLOR][COLOR= #007700]);[/COLOR]
    
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sRowCount[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700])
    {[/COLOR]
        [COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"gebruikersnaam"[/COLOR][COLOR= #007700]] =[/COLOR] [COLOR= #0000BB]$gebruikersnaam[/COLOR][COLOR= #007700];[/COLOR] 
         [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"LOCATION: login_success.php"[/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]"Verkeerde gebruikersnaam of wachtwoord"[/COLOR][COLOR= #007700];
     }[/COLOR]
    
 ?>


Zie ook dat ik wachtwoord in session weg heb gehaald. Het opslaan van wachtwoorden in cookies of sessions is echt een big NO-GO.
Owja sorry ik zie het, ik dacht dat $result de fetch van $sql was, maar hij doet een query in 2 regels..?
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