PHP/MySQL probleem

Gestart doorJob7 reacties520 weergaven

8 berichten · pagina 1 van 1

Job

Lid · Topicstarter

Berichten
425
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hallo allemaal,
Ondanks mijn afwezigheid hier zit ik niet stil. Nu heb ik een probleem waar ik tegenaan loop. Waarschijnlijk kijk ik gewoon ergens overheen maargoed. Ik probeer n registreer-script te maken.

Codeblok (registreren.php):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31


include(header.php); ?>

include(profilediv.php); ?>
include(footer.php); ?>


Codeblok (registreerv.php):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35


include(header.php); ?>

include(profilediv.php); ?>


if(isset($_POST[submit])) {
if(!empty($_POST[user]) AND !empty($_POST[password]) AND !empty($_POST[email])) {
$user = mysql_real_escape_string($_POST[user]);
$password = sha1($_POST[password]);
$mail = mysql_real_escape_string($_POST[email]);
$sql = ("SELECT user FROM users WHERE user=". $user . "");
$uitvoer = mysql_query($sql);

$controle = mysql_num_rows($uitvoer);

if($controle == 0) {
mysql_query("INSERT INTO users (user, password, email) VALUES (," . $user . ", " . $password . ", " . $mail . ")");
echo U bent succesvol geregistreerd!;

}
else{
echo Er is iets foutgegaan;
}
}
}


?>
include(footer.php); ?>


De gegevens komen niet in Phpmyadmin terecht! Wel krijg ik de melding "U bent succesvol geregistreerd!". Weet iemand hoe dit op te lossen?

Groeten Job
0
Berichten
13.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hey Job. @Job

De INSERT query klopt niet. Je geeft in de query aan dat je 3 velden meegeeft (user, password, email), maar daar wil je 4 waarden in stoppen (leeg, user, password, mail)

Ik raad je overigens aan om PDO te gebruiken voor je verbinding met MySQL.
0
Job

Lid · Topicstarter

Berichten
425
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hi Sjoerd, allereerst dankjewel voor je reactie. Ik ga zo kijken of het werkt. Vraagje wat betreft PDO, is PDO een grote stap om te maken vanaf regulier PHP/MySQL? Of als in, gaat er heel veel tijd in zitten?

Edit!
Registreren werkt nu, inloggen alleen nog niet! Hij herkent bij de controle de gegevens niet.

<html>
    [COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]header.php[/COLOR][COLOR= #007700]);[/COLOR] ?>
        <div id="page">            
            
            [COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]profilediv.php[/COLOR][COLOR= #007700]);[/COLOR] ?>
            <div id="register">
            <form method="post" action="inloggen.php">
                <table>
                    <tr>
                    <td>Gebruikersnaam:</td>
                    <td><input type="text" name="user" value="" placeholder="Gebruikersnaam"></td>
                    </tr>
                    
                    <tr>
                    <td>Wachtwoord:</td>
                    <td><input type="password" name="password" value="" placeholder="Wachtwoord"</td>
                    </tr>
                    <tr><td></td>
                    <td><input type="submit" name="submit" value="Inloggen">
                    </td></tr>
                </table>
            
            </form>
            </div>
                        
            [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]        [COLOR= #FF8000]// Controle of er op de knop is gedrukt.[/COLOR]
[COLOR= #007700]{[/COLOR]
          
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700](![/COLOR][URL="http://www.php.net/empty"]empty[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]user[/COLOR][COLOR= #007700]])[/COLOR] AND [COLOR= #007700]![/COLOR][URL="http://www.php.net/empty"]empty[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]password[/COLOR][COLOR= #007700]])) 
    {[/COLOR]
        [COLOR= #0000BB]$user[/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]user[/COLOR][COLOR= #007700]]);[/COLOR]  
        [COLOR= #0000BB]$password[/COLOR]        [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/sha1"]sha1[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]password[/COLOR][COLOR= #007700]]);[/COLOR]  
        [COLOR= #0000BB]$sql[/COLOR] [COLOR= #007700]= ([/COLOR][COLOR= #DD0000]"SELECT user, password FROM users WHERE user="[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$user[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]" AND password="[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$password[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700]);[/COLOR] 
        [COLOR= #0000BB]$uitvoer[/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]$controle[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$uitvoer[/COLOR][COLOR= #007700]);[/COLOR] 
            [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$controle[/COLOR] [COLOR= #007700]!=[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700])
            {[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Test[/COLOR][COLOR= #007700];
            }[/COLOR]
            [URL="http://www.php.net/else"]else[/URL]
            [COLOR= #007700]{[/COLOR]
                [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]Refresh: 2; url=inloggen.php[/COLOR][COLOR= #007700]);[/COLOR]
                [URL="http://www.php.net/exit"]exit[/URL] [COLOR= #007700]([/COLOR][COLOR= #DD0000]Verkeerde gebruikersnaam of wachtwoord.[/COLOR][COLOR= #007700]);[/COLOR]        [COLOR= #FF8000]// Negatieve melding van ingevoerde gegevens.[/COLOR]
            [COLOR= #007700]}            
    }
}[/COLOR]
?>
        </div>
    [COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]footer.php[/COLOR][COLOR= #007700]);[/COLOR] ?>
</html>


Geen idee waar het fout gaat..
0
Stef

Lid

Berichten
10.150
Reputatie
2
Punten
0,00
Lid sinds
Laatst gezien
Job schreef:
Hi Sjoerd, allereerst dankjewel voor je reactie. Ik ga zo kijken of het werkt. Vraagje wat betreft PDO, is PDO een grote stap om te maken vanaf regulier PHP/MySQL? Of als in, gaat er heel veel tijd in zitten?

Edit!
Registreren werkt nu, inloggen alleen nog niet! Hij herkent bij de controle de gegevens niet.

<html>
    [COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]header.php[/COLOR][COLOR= #007700]);[/COLOR] ?>
        <div id="page">            
            
            [COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]profilediv.php[/COLOR][COLOR= #007700]);[/COLOR] ?>
            <div id="register">
            <form method="post" action="inloggen.php">
                <table>
                    <tr>
                    <td>Gebruikersnaam:</td>
                    <td><input type="text" name="user" value="" placeholder="Gebruikersnaam"></td>
                    </tr>
                    
                    <tr>
                    <td>Wachtwoord:</td>
                    <td><input type="password" name="password" value="" placeholder="Wachtwoord"</td>
                    </tr>
                    <tr><td></td>
                    <td><input type="submit" name="submit" value="Inloggen">
                    </td></tr>
                </table>
            
            </form>
            </div>
                        
            [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]        [COLOR= #FF8000]// Controle of er op de knop is gedrukt.[/COLOR]
[COLOR= #007700]{[/COLOR]
          
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700](![/COLOR][URL="http://www.php.net/empty"]empty[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]user[/COLOR][COLOR= #007700]])[/COLOR] AND [COLOR= #007700]![/COLOR][URL="http://www.php.net/empty"]empty[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]password[/COLOR][COLOR= #007700]])) 
    {[/COLOR]
        [COLOR= #0000BB]$user[/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]user[/COLOR][COLOR= #007700]]);[/COLOR]  
        [COLOR= #0000BB]$password[/COLOR]        [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/sha1"]sha1[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]password[/COLOR][COLOR= #007700]]);[/COLOR]  
        [COLOR= #0000BB]$sql[/COLOR] [COLOR= #007700]= ([/COLOR][COLOR= #DD0000]"SELECT user, password FROM users WHERE user="[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$user[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]" AND password="[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$password[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700]);[/COLOR] 
        [COLOR= #0000BB]$uitvoer[/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]$controle[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$uitvoer[/COLOR][COLOR= #007700]);[/COLOR] 
            [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$controle[/COLOR] [COLOR= #007700]!=[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700])
            {[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Test[/COLOR][COLOR= #007700];
            }[/COLOR]
            [URL="http://www.php.net/else"]else[/URL]
            [COLOR= #007700]{[/COLOR]
                [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]Refresh: 2; url=inloggen.php[/COLOR][COLOR= #007700]);[/COLOR]
                [URL="http://www.php.net/exit"]exit[/URL] [COLOR= #007700]([/COLOR][COLOR= #DD0000]Verkeerde gebruikersnaam of wachtwoord.[/COLOR][COLOR= #007700]);[/COLOR]        [COLOR= #FF8000]// Negatieve melding van ingevoerde gegevens.[/COLOR]
            [COLOR= #007700]}            
    }
}[/COLOR]
?>
        </div>
    [COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]footer.php[/COLOR][COLOR= #007700]);[/COLOR] ?>
</html>
Geen idee waar het fout gaat..

Nou niet per se PDO maar wel MySQLi aangezien MySQL sterk verouderd is.
Ik vind persoonlijk PDO niet fijn werken.
0
Berichten
951
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
je bent in iedergeval vergeten je password input af te sluiten.

verder zie ik niks verkeerd zo snel.

Al kun je beter overstappen op Mysqli IPV mysql
0
Job

Lid · Topicstarter

Berichten
425
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hmm, ook na dat verholpen te hebben krijg ik nog steeds de melding dat de combinatie verkeerd is.
0
Berichten
13.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hoe lang is het veld voor password in je database? Misschien is de sha1 hash van je wachtwoord langer dan de maximale lengte, waardoor hij de sha1-hash afkort bij de insert..

toevoeging op 28 november 2015, 20:22:50:
@Job
0
Job

Lid · Topicstarter

Berichten
425
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
@Sjoerd , Ja, het werkt, inderdaad was de lengte van het veld de issue. Tnx voor je hulp!
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