Register page wat is er fout?
nu ben ik zelf gewoon een website aan het maken...
maar mijn register page doet het niet ik kan het zelf niet vinden
hopelijk kunnen jullie me ermee helpen:D
Code (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
<!DOCTYPE html>
<html>
<head>
<title>Register</title>
<link type="text/css" rel="stylesheet" href="style/register.css">
</head>
<body>
<form action="index.php" method="post">
<div id="bg">
<div id="top"></div>
<div id="left"></div>
<a id="username">Choose you'r username!</a>
<div id="username"></div>
<input id="username" type="text" name="username" />
<a id="password">Choose you'r password!</a>
<div id="password"></div>
<input id="password" type="password" name="password" />
<a id="cpassword">Confirm you'r password!</a>
<div id="cpassword"></div>
<input id="cpassword" type="password" name="cpassword" />
<a id="email">Fill in you'r E-Mail!</a>
<div id="email"></div>
<input id="email" type="email" name="email" />
<a id="cemail">Confirm you'r E-Mail!</a>
<div id="cemail"></div>
<input id="cemail" type="email" name="cemail" />
<a id="name">Fill in you'r name!</a>
<div id="name"></div>
<input id="name" type="text" name="name" />
<a id="age">Fill in you'r age!</a>
<div id="age"></div>
<input id="age" type="text" name="age" />
<input id="submitregister" type="submit" value="Register" />
<div id="right"></div>
<div id="bottom"></div>
</div>
</form>
<?php
$connection = null;
if(isset($_POST['username']) and isset($_POST['password']) and isset($_POST['cpassword']) and isset($_POST['email']) and isset($_POST['cemail']) and isset($_POST['name']) and isset($_POST['age'])){
dbConnect();
dbSave();
mysql_close($GLOBALS['connection']);
}
function dbConnect(){
$host = 'localhost';
$user = 'root';
$password = '123';
$db = 'website';
$GLOBALS['connection'] = mysql_connect($host, $user, $password);
$db = mysql_select_db($db);
if(!$GLOBALS['connection']){
die ("Could not connect: " . mysql_error());
}
}
function dbSave(){
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$email = $_POST['email'];
$cemail = $_POST['cemail'];
$name = mysql_real_escape_string($_POST['name']);
$age = is_numeric($_POST['age']);
$save = "
INSERT INTO website
(
username,
password,
email,
name,
age
)
VALUES
(
'$username',
'$password',
'$email',
'$name',
'$age',
)
";
if(!$res = mysql_query($save)){
trigger_error(mysql_error().'<br>In Query: '.$save);
}
}
?>
</body>
</html>
?>
<!DOCTYPE html>
<html>
<head>
<title>Register</title>
<link type="text/css" rel="stylesheet" href="style/register.css">
</head>
<body>
<form action="index.php" method="post">
<div id="bg">
<div id="top"></div>
<div id="left"></div>
<a id="username">Choose you'r username!</a>
<div id="username"></div>
<input id="username" type="text" name="username" />
<a id="password">Choose you'r password!</a>
<div id="password"></div>
<input id="password" type="password" name="password" />
<a id="cpassword">Confirm you'r password!</a>
<div id="cpassword"></div>
<input id="cpassword" type="password" name="cpassword" />
<a id="email">Fill in you'r E-Mail!</a>
<div id="email"></div>
<input id="email" type="email" name="email" />
<a id="cemail">Confirm you'r E-Mail!</a>
<div id="cemail"></div>
<input id="cemail" type="email" name="cemail" />
<a id="name">Fill in you'r name!</a>
<div id="name"></div>
<input id="name" type="text" name="name" />
<a id="age">Fill in you'r age!</a>
<div id="age"></div>
<input id="age" type="text" name="age" />
<input id="submitregister" type="submit" value="Register" />
<div id="right"></div>
<div id="bottom"></div>
</div>
</form>
<?php
$connection = null;
if(isset($_POST['username']) and isset($_POST['password']) and isset($_POST['cpassword']) and isset($_POST['email']) and isset($_POST['cemail']) and isset($_POST['name']) and isset($_POST['age'])){
dbConnect();
dbSave();
mysql_close($GLOBALS['connection']);
}
function dbConnect(){
$host = 'localhost';
$user = 'root';
$password = '123';
$db = 'website';
$GLOBALS['connection'] = mysql_connect($host, $user, $password);
$db = mysql_select_db($db);
if(!$GLOBALS['connection']){
die ("Could not connect: " . mysql_error());
}
}
function dbSave(){
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$email = $_POST['email'];
$cemail = $_POST['cemail'];
$name = mysql_real_escape_string($_POST['name']);
$age = is_numeric($_POST['age']);
$save = "
INSERT INTO website
(
username,
password,
email,
name,
age
)
VALUES
(
'$username',
'$password',
'$email',
'$name',
'$age',
)
";
if(!$res = mysql_query($save)){
trigger_error(mysql_error().'<br>In Query: '.$save);
}
}
?>
</body>
</html>
?>
Ook open je bovenaan boven je html < ? php , weet niet of je dat alleen hier doet of ook in je script, maar die mag je weghalen
Gewijzigd op 09/02/2014 12:30:16 door D B
ja dat < ? php open ik hier en hij gaat gwn naar de volgende pagina en doet niks
En kijk eens wat hij dan aangeeft
Zet error-reporting aan (helemaal boven in je script).
Waarom de functie dbSave? Je kunt deze maar op 1 manier aanroepen.
Waarom in die functie nieuwe variabelen aanmaken?
Je controleert nergens of de waarden voldoen aan criteria, maar 'ploft' alles in de database.
Waarom een leeftijd invullen? Die kan morgen alweer achterhaalt zijn.
Waarom die mysql_real_escape_string niet gewoon in de query?
Verder is het doorgaans logischer om in een script te beginnen met controle / verwerken (php / mysql) en dan pas output.
Zou afstappen van mysql maar overstappen op mysqli of pdo.
Code (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL | E_STRICT);
$connection = null;
if(isset($_POST['username']) and isset($_POST['password']) and isset($_POST['cpassword']) and isset($_POST['email']) and isset($_POST['cemail']) and isset($_POST['name']) and isset($_POST['age'])){
dbConnect();
dbSave();
mysql_close($GLOBALS['connection']);
}else{
echo 'All fields have to be filled in!';
}
function dbConnect(){
$host = 'localhost';
$user = 'root';
$password = '123';
$db = 'website';
$GLOBALS['connection'] = mysql_connect($host, $user, $password);
$db = mysql_select_db($db);
if(!$GLOBALS['connection']){
die ("Could not connect: " . mysql_error());
}
}
function dbSave(){
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$email = $_POST['email'];
$cemail = $_POST['cemail'];
$name = mysql_real_escape_string($_POST['name']);
$age = is_numeric($_POST['age']);
$save = ("
INSERT INTO website
(
username,
password,
email,
name,
age
)
VALUES
(
'$username',
'$password',
'$email',
'$name',
'$age',
)
");
if(!$res = mysql_query($save)){
trigger_error(mysql_error().'<br>In Query: '.$save);
}
}
?>
ini_set('display_errors', 1);
error_reporting(E_ALL | E_STRICT);
$connection = null;
if(isset($_POST['username']) and isset($_POST['password']) and isset($_POST['cpassword']) and isset($_POST['email']) and isset($_POST['cemail']) and isset($_POST['name']) and isset($_POST['age'])){
dbConnect();
dbSave();
mysql_close($GLOBALS['connection']);
}else{
echo 'All fields have to be filled in!';
}
function dbConnect(){
$host = 'localhost';
$user = 'root';
$password = '123';
$db = 'website';
$GLOBALS['connection'] = mysql_connect($host, $user, $password);
$db = mysql_select_db($db);
if(!$GLOBALS['connection']){
die ("Could not connect: " . mysql_error());
}
}
function dbSave(){
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$email = $_POST['email'];
$cemail = $_POST['cemail'];
$name = mysql_real_escape_string($_POST['name']);
$age = is_numeric($_POST['age']);
$save = ("
INSERT INTO website
(
username,
password,
email,
name,
age
)
VALUES
(
'$username',
'$password',
'$email',
'$name',
'$age',
)
");
if(!$res = mysql_query($save)){
trigger_error(mysql_error().'<br>In Query: '.$save);
}
}
?>
Ik heb dus ook een else statement aangemaakt na het 1e if statement! wat nu?
Toevoeging op 09/02/2014 12:52:25:
en als ik nu dus niet alles heb ingevuld dan geeft ie dus aan van dat niet alles is ingevuld
Functions zou ik nog boven het if-statement plaatsen.
Krijg je ondertussen al een foutmelding?
Dus eigenlijk werkt het script nu, alleen schrijft hij niet weg?
Toevoeging op 09/02/2014 12:56:24:
achter $age staat een komma die daar niet hoort,
Gewijzigd op 09/02/2014 12:56:59 door D B
D B op 09/02/2014 12:53:41:
achter $age staat een komma die daar niet hoort,
Dat zou een foutmelding moeten geven...
Dat dacht ik dus ook :)
Obelix ehm dat was het dus die komma moest weg maar hij gaf daarvoor geen foutmelding aan:P maar dankje:D
Code (php)
1
2
3
4
5
6
2
3
4
5
6
<?
if(!$res = mysql_query($save)){
trigger_error(mysql_error().'<br>In Query: '.$save);
}
}
?>
if(!$res = mysql_query($save)){
trigger_error(mysql_error().'<br>In Query: '.$save);
}
}
?>
Dit is de foutafhandeling van je Query, waarschijnlijk mist daar dus iets.... Bijvoorbeeld echo
Ik weet niet zo goed wat trigger_error(mysql_error().'<br>In Query: '.$save); doet....
maar als je daar gewoon neer zet (om te testen) echo 'Fout';
Zou je wel degelijk een melding moeten krijgen.
Toevoeging op 09/02/2014 13:32:51:
maar ik had zelf ook nog een fout gemaakt en dat was in het stukje van MySQL want ik zei dus INSERT INTO website maar het was INTO accounts xD
Toevoeging op 09/02/2014 13:33:43:
oke nu doet het wel maar hij checkt dus niet of het is ingevult bij het stukje
Code (php)
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
<?php $connection = null;
if($_POST['password'] == $_POST['cpassword'] and $_POST['email'] == $_POST['cemail']){
if(isset($_POST['username']) and isset($_POST['password']) and isset($_POST['cpassword']) and isset($_POST['email']) and isset($_POST['cemail']) and isset($_POST['name']) and isset($_POST['age'])){
dbConnect();
dbSave();
mysql_close($GLOBALS['connection']);
}else{
echo '<div id="error"><br>All fields have to be filled in!</div>';
}
} ?>
if($_POST['password'] == $_POST['cpassword'] and $_POST['email'] == $_POST['cemail']){
if(isset($_POST['username']) and isset($_POST['password']) and isset($_POST['cpassword']) and isset($_POST['email']) and isset($_POST['cemail']) and isset($_POST['name']) and isset($_POST['age'])){
dbConnect();
dbSave();
mysql_close($GLOBALS['connection']);
}else{
echo '<div id="error"><br>All fields have to be filled in!</div>';
}
} ?>
Toevoeging op 09/02/2014 13:34:33:
en het checken of password en cpassword en/of email en cemail gelijk zijn
Maar eigenlijk moet je daar verder uitgewerkte controles op uitvoeren.... bijvoorbeeld een lengte of bepaalde tekens die er wel en niet in voor mogen komen.
- isset kan meerdere argumenten tegelijk aan, je hele isset check kan dus een stuk overzichtelijker:
Code (php)
- je beschermt wel username, password en name, maar niet email. Waarom niet?
- je slaat het password niet encrypted op, dat is een slechte gewoonte, want bij een hack liggen alle passwords op straat
- is_numeric geeft een boolean terug. Bij iedereen zal de leeftijd nu dus 0 of 1 worden.
- om integers in een query hoef hoef je geen quotes te plaatsen. Als je er dus voor zorgt dat $age altijd een integer is kunnen die quotes weg.
wat is er dan fout?
dit is lijn 41:
Je mist een )
Toevoeging op 09/02/2014 14:12:23:
oke wanneer ik niets of niet alles heb ingevuld registreert ie alsnog
hoezo dat dit is mijn hele php code!
Code (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
$connection = null;
if(!isset($_POST['username'], $_POST['password'], $_POST['cpassword'], $_POST['email'], $_POST['cemail'], $_POST['name'], $_POST['age'])){
echo '<div id="error"><br>All fields have to be filled in!</div>';
}else{
dbConnect();
dbSave();
mysql_close($GLOBALS['connection']);
}
function dbConnect(){
$host = 'localhost';
$user = 'root';
$password = '123';
$db = 'website';
$GLOBALS['connection'] = mysql_connect($host, $user, $password);
$db = mysql_select_db($db);
if(!$GLOBALS['connection']){
die ("Could not connect: " . mysql_error());
}
}
function dbSave(){
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$email = $_POST['email'];
$cemail = $_POST['cemail'];
$name = mysql_real_escape_string($_POST['name']);
$age = is_numeric($_POST['age']);
$save = ("
INSERT INTO accounts
(
username,
password,
email,
name,
age
)
VALUES
(
'$username',
'$password',
'$email',
'$name',
'$age'
)
");
if(!$res = mysql_query($save)){
trigger_error(mysql_error().'<br>In Query: '.$save);
}
}
?>
$connection = null;
if(!isset($_POST['username'], $_POST['password'], $_POST['cpassword'], $_POST['email'], $_POST['cemail'], $_POST['name'], $_POST['age'])){
echo '<div id="error"><br>All fields have to be filled in!</div>';
}else{
dbConnect();
dbSave();
mysql_close($GLOBALS['connection']);
}
function dbConnect(){
$host = 'localhost';
$user = 'root';
$password = '123';
$db = 'website';
$GLOBALS['connection'] = mysql_connect($host, $user, $password);
$db = mysql_select_db($db);
if(!$GLOBALS['connection']){
die ("Could not connect: " . mysql_error());
}
}
function dbSave(){
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$email = $_POST['email'];
$cemail = $_POST['cemail'];
$name = mysql_real_escape_string($_POST['name']);
$age = is_numeric($_POST['age']);
$save = ("
INSERT INTO accounts
(
username,
password,
email,
name,
age
)
VALUES
(
'$username',
'$password',
'$email',
'$name',
'$age'
)
");
if(!$res = mysql_query($save)){
trigger_error(mysql_error().'<br>In Query: '.$save);
}
}
?>
Zo blijft je script lek.
Mathieu Posthumus op 09/02/2014 13:59:43:
Hiermee controleer je toch alleen maar of de genoemde velden worden doorgegeven vanuit het formulier. Er vindt geen enkele check plaats of er ook een waarde in die velden zit.
- SanThe - op 09/02/2014 14:28:37:
Waarom beveilig je niet alle input?
Zo blijft je script lek.
Zo blijft je script lek.
Tsja, dat had ik in mijn vorige post ook al gezet, maar verder dan de eerste regel is de TS blijkbaar niet gekomen. Net als dat iedereen nog steeds 0 of 1 jaar oud blijft.
Geeft weinig motivatie om nog verdere tips te geven....