fout in loginscript

Gestart doorEpicrobzer23 reacties72 weergaven

24 berichten · pagina 1 van 2

Epicrobzer

Lid · Topicstarter

Berichten
4.036
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hoi,

dit is de fout:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/sevenft/domains/7ft.nl/public_html/adminlogin.php on line 16


En dit is me .php:

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

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

[COLOR= #0000BB]$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]

[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$gebruikersnaam[/COLOR][COLOR= #007700]&&[/COLOR][COLOR= #0000BB]$wachtwoord[/COLOR][COLOR= #007700])
{[/COLOR]

        [COLOR= #0000BB]$connect[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_connect"]mysql_connect[/URL] [COLOR= #007700]([/COLOR][COLOR= #DD0000]"localhost"[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]"****"[/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 communiceren met de database"[/COLOR]                [COLOR= #007700]);[/COLOR]
        [URL="http://www.php.net/mysql_select_db"]mysql_select_db[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"sevenft_login"[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL] [COLOR= #007700]([/COLOR][COLOR= #DD0000]"Onvindbaar in de database"[/COLOR][COLOR= #007700]);[/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 users WHERE gebruikersnaam=$gebruikersnaam "[/COLOR][COLOR= #007700]);[/COLOR] 
        
        [COLOR= #0000BB]$numrows[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR][COLOR= #007700]);[/COLOR] 
        
        [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$numrows[/COLOR] [COLOR= #007700]!=[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700])
        
        {[/COLOR]
        
        [URL="http://www.php.net/while"]while[/URL]  [COLOR= #007700]([/COLOR][COLOR= #0000BB]$row[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR][COLOR= #007700]))
        
        {[/COLOR]
        
            [COLOR= #0000BB]$dbgebruikersnaam[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$row[/COLOR] [COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]];[/COLOR]
            [COLOR= #0000BB]$dbwachtwoord[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$row[/COLOR] [COLOR= #007700][[/COLOR][COLOR= #DD0000]wachtwoord[/COLOR][COLOR= #007700]];        
        
        }[/COLOR]
            [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$gebruikersnaam[/COLOR][COLOR= #007700]==[/COLOR][COLOR= #0000BB]$dbgebruikersnaam[/COLOR][COLOR= #007700]&&[/COLOR][COLOR= #0000BB]$wachtwoord[/COLOR][COLOR= #007700]==[/COLOR][COLOR= #0000BB]$dbwachtwoord[/COLOR][COLOR= #007700])
            
            {[/COLOR]
            
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Succesvol ingelogd. <a href=admpanel.php>Klik hier om door te gaan naar het Admin Paneel."[/COLOR][COLOR= #007700];[/COLOR]
                [COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]]=[/COLOR][COLOR= #0000BB]$dbgebruikersnaam[/COLOR][COLOR= #007700];
                
                     
                
            
            }[/COLOR]
            [URL="http://www.php.net/else"]else[/URL]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Verkeerd wachtwoord"[/COLOR][COLOR= #007700];
        }[/COLOR]
        [URL="http://www.php.net/else"]else[/URL]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Deze gebruikersnaam bestaat niet"[/COLOR][COLOR= #007700]; 
        
    
}[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL]
    [URL="http://www.php.net/die"]die[/URL] [COLOR= #007700]([/COLOR][COLOR= #DD0000]"Voer een gebruiksnaam en wachtwoord in alstublieft"[/COLOR][COLOR= #007700])[/COLOR]
?>


ik weet niet hoe ik dit moet oplossen want ik ben nog een beginner.

Groetjes,
Robin
0
Berichten
5.498
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Lange tijd geleden dat ik met PHP heb gewerkt dus weet niet of het werkt maar proberen kan natuurlijk altijd smile!

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

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

[COLOR= #0000BB]$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]

[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$gebruikersnaam[/COLOR][COLOR= #007700]&&[/COLOR][COLOR= #0000BB]$wachtwoord[/COLOR][COLOR= #007700])
{[/COLOR]

        [COLOR= #0000BB]$connect[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_connect"]mysql_connect[/URL] [COLOR= #007700]([/COLOR][COLOR= #DD0000]"localhost"[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]"****"[/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 communiceren met de database"[/COLOR]                [COLOR= #007700]);[/COLOR]
        [URL="http://www.php.net/mysql_select_db"]mysql_select_db[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"sevenft_login"[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL] [COLOR= #007700]([/COLOR][COLOR= #DD0000]"Onvindbaar in de database"[/COLOR][COLOR= #007700]);[/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 users WHERE gebruikersnaam="[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$gebruikersnaam[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]" "[/COLOR][COLOR= #007700]);[/COLOR] 
        
        [COLOR= #0000BB]$numrows[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR][COLOR= #007700]);[/COLOR] 
        
        [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$numrows[/COLOR] [COLOR= #007700]!=[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700])
        
        {[/COLOR]
        
        [URL="http://www.php.net/while"]while[/URL]  [COLOR= #007700]([/COLOR][COLOR= #0000BB]$row[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR][COLOR= #007700]))
        
        {[/COLOR]
        
            [COLOR= #0000BB]$dbgebruikersnaam[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$row[/COLOR] [COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]];[/COLOR]
            [COLOR= #0000BB]$dbwachtwoord[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$row[/COLOR] [COLOR= #007700][[/COLOR][COLOR= #DD0000]wachtwoord[/COLOR][COLOR= #007700]];        
        
        }[/COLOR]
            [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$gebruikersnaam[/COLOR][COLOR= #007700]==[/COLOR][COLOR= #0000BB]$dbgebruikersnaam[/COLOR][COLOR= #007700]&&[/COLOR][COLOR= #0000BB]$wachtwoord[/COLOR][COLOR= #007700]==[/COLOR][COLOR= #0000BB]$dbwachtwoord[/COLOR][COLOR= #007700])
            
            {[/COLOR]
            
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Succesvol ingelogd. <a href=admpanel.php>Klik hier om door te gaan naar het Admin Paneel."[/COLOR][COLOR= #007700];[/COLOR]
                [COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]]=[/COLOR][COLOR= #0000BB]$dbgebruikersnaam[/COLOR][COLOR= #007700];
                
                     
                
            
            }[/COLOR]
            [URL="http://www.php.net/else"]else[/URL]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Verkeerd wachtwoord"[/COLOR][COLOR= #007700];
        }[/COLOR]
        [URL="http://www.php.net/else"]else[/URL]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Deze gebruikersnaam bestaat niet"[/COLOR][COLOR= #007700]; 
        
    
}[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Voer een gebruiksnaam en wachtwoord in alstublieft"[/COLOR][COLOR= #007700];[/COLOR]
?>
0
Epicrobzer

Lid · Topicstarter

Berichten
4.036
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Werkt niet cry. Nog steeds dezelfde fout.

Hij zegt dat het account niet bestaat, maar het account bestaat wel degelijk in de database.
0
Berichten
5.498
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Maar je gebruikt "POST" bij dit script, kan je de pagina eens laten zien vanaf waar je post?
0
Epicrobzer

Lid · Topicstarter

Berichten
4.036
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="adminlogin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Adminlogin</strong></td>
</tr>
<tr>
<td width="78">Gebruikersnaam</td>
<td width="6">:</td>
<td width="294"><input name="gebruikersnaam" type="text" id="gebruikersnaam"></td>
</tr>
<tr>
<td>Wachtwoord</td>
<td>:</td>
<td><input name="wachtwoord" type="password" id="wachtwoord"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>


Bedoel je deze? of wat bedoel je?
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Algemeen slecht gescript :|

"SELECT * FROM users WHERE gebruikersnaam=$gebruikersnaam " | regel 14 naar
"SELECT * FROM users WHERE gebruikersnaam=".$gebruikersnaam.""
0
Berichten
5.498
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Antonn schreef:
Algemeen slecht gescript :|
"SELECT * FROM users WHERE gebruikersnaam=$gebruikersnaam " | regel 14 naar
"SELECT * FROM users WHERE gebruikersnaam=".$gebruikersnaam.""

Ja, dat had ik dus al veranderd emo
0
Berichten
5.897
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
In je HTML staat name="password" en in je PHP $_POST[wachtwoord]
0
Berichten
5.498
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Maartenl schreef:
In je HTML staat name="password" en in je PHP $_POST[wachtwoord]
Slim gezien yummie
Maar ben het wel eens met Anton, slecht gescript ^^
0
Epicrobzer

Lid · Topicstarter

Berichten
4.036
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Joh het is me eerste script. Ik doe het om er iets van de leren.

@ Maartenl, veranderd maar werkt niet.
0
Berichten
5.897
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Geen mysql_real_escape_string()
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Het hele script is fout:

- die() hoor je niet te gebruiken, je script moet nooit stoppen, maar altijd doorgaan, en eventuele fouten handel je altijd netjes af met if-else. Ik zie dat dit net al is aangepast.

- Waarom gebruik je een while() als je toch maar 1 record hebt?

- Waarom kopieer je variabelen (o.a op lijn 26 en 27)

- SQL injection is mogelijk. Iedereen kan met wat mazzel je hele database doorzoeken. Escape je variabelen met mysql_real_escape_string()

- Ik mis foutafhandeling op je query. Lees ook dit artikel eens, en pas dit eens toe.

- Verder mis een controle of je forumlierdata ge-POSt is met: if($_SERVER[REQUEST_METHOD] == "POST" )

Tijd om dit weg te gooien, en from scratch helemaal opnieuw te beginnen.
0
Berichten
5.897
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Waarom een while in een inlogscript ? emo^was net eerder sadley
0
Berichten
5.498
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Epicrobzer schreef:
Joh het is me eerste script. Ik doe het om er iets van de leren.

Oké, dan is t geen probleem natuurlijk winkIk dacht dat je dit op je site ging gebruiken ofzo en gebruik inderdaad zoals Maarten zegt "mysql_real_escape_string()"

Dat doe je zo:
Verander regel 14 naar:

$query = mysql_query ("SELECT * FROM users WHERE gebruikersnaam=".mysql_real_escape_string($gebruikersnaam)." ");
En dan zou ik ook eens kijken naar de dingen die AarClay hierboven noemt wink
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
En tabellen voor een formulier kan ik niet echt aanraden.
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