probleem met validatie registratieformulier
Nu zou ik graag mijn registratieformulier willen valideren.
(checken of confirmpassword gelijk is aan password)
(checken of het emailadres correct is)
Ik heb al geprobeerd om ervoor te zorgen dat de 2 paswoorden aan elkaar gelijk zijn door een feedbackveldje aan te maken die zou moeten verschijnen indien ze niet gelijk zijn. Wat er gebeurt is dat de pagina gewoon vernieuwt en dat alle invulvelden terug leegzijn. Van het feedbackveldje is ook niets te zien.
kan iemand mij helpen?
dit is de code van registration.html
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
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
<?php
$feedback = "";
include('classes/User.php');
if(!empty($_POST['UserName'])&& !empty($_POST['Password'])&& !empty($_POST['Confirmpassword'])&& !empty($_POST['FirstName'])
&& !empty($_POST['LastName'])&& !empty($_POST['Email'])&& !empty($_POST['Gender'])){
try
{
$oUser = new User();
$oUser->Username = $_POST['UserName'];
$oUser->Password = $_POST['Password'];
$oUser->Confirmpassword = $_POST['Confirmpassword'];
$oUser->Firstname = $_POST['FirstName'];
$oUser->Lastname = $_POST['LastName'];
$oUser->Email = $_POST['Email'];
$oUser->Gender = $_POST['Gender'];
$oUser->Save();
}
catch (Exception $e)
{
$feedback = $e->getMessage();
}
}
}
?>
$feedback = "";
include('classes/User.php');
if(!empty($_POST['UserName'])&& !empty($_POST['Password'])&& !empty($_POST['Confirmpassword'])&& !empty($_POST['FirstName'])
&& !empty($_POST['LastName'])&& !empty($_POST['Email'])&& !empty($_POST['Gender'])){
try
{
$oUser = new User();
$oUser->Username = $_POST['UserName'];
$oUser->Password = $_POST['Password'];
$oUser->Confirmpassword = $_POST['Confirmpassword'];
$oUser->Firstname = $_POST['FirstName'];
$oUser->Lastname = $_POST['LastName'];
$oUser->Email = $_POST['Email'];
$oUser->Gender = $_POST['Gender'];
$oUser->Save();
}
catch (Exception $e)
{
$feedback = $e->getMessage();
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Jongerenhulp-Registratie</title>
<link rel="stylesheet" href="css/screen.css" type="text/css"/>
</head>
<body>
<div id="wrapper">
<img src="images/emotions.jpg" alt="" width="1024" height="1000" />
<div id="registerform">
<form id='register' action='' method="post">
<fieldset>
<legend accesskey="y">About You</legend>
<table>
<tr>
<td><label for="userName">User name:</label></td>
<td><input type="text" name="UserName" size="20" id="userName" /></td>
</tr>
<tr>
<td><label for="password">Password:</label></td>
<td><input type="password" name="Password" size="20" id="password" /></td>
</tr>
<tr>
<td><label for="confPassword">Confirm Password:</label></td>
<td><input type="password" name="Confirmpassword" size="20" id="confPassword" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><label for="firstName">First name:</label></td>
<td><input type="text" name="FirstName" size="20" id="firstName" /></td>
</tr>
<tr>
<td><label for="lastName">Last name:</label></td>
<td><input type="text" name="LastName" size="20" id="lastName" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><label for="email">Email address:</label></td>
<td><input type="text" name="Email" size="20" id="email" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Gender:</td>
<td><input type="radio" name="Gender" value="male" />Male</td>
</tr>
<tr>
<td></td>
<td><input type="radio" name="Gender" value="female" />Female</td>
</tr>
<tr><td> </td><td> </td></tr>
<td><input type="submit" name="btnsubmit" size="20" id="btnsubmit" value="Registreer" /></td>
</table>
</fieldset>
</form>
</div>
<div id="feedback">
</div>
</div>
</body>
</html>
dit is de code van de User klasse
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
class User
{
//EIGENSCHAPPEN
private $m_sUsername;
private $m_sPassword;
private $m_sConfirmpassword;
private $m_sFirstname;
private $m_sLastname;
private $m_sEmail;
private $m_sGender;
private $m_sHost = "localhost";
private $m_sUser = "root";
private $m_sPass = "";
private $m_sDatabase = "phpproject";
//GETTER
function __get($p_sProperty)
{
switch($p_sProperty)
{
case "Username":
return $this->m_sUsername;
break;
case "Password":
return $this->m_sPassword;
break;
case "Confirmpassword":
return $this->m_sConfirmpassword;
break;
case "Firstname":
return $this->m_sFirstname;
break;
case "Lastname":
return $this->m_sLastname;
break;
case "Email":
return $this->m_sEmail;
break;
case "Gender":
return $this->m_sGender;
break;
}
}
//SETTER
function __set($p_sProperty, $p_vValue)
{
switch($p_sProperty)
{
case "Username":
$this->m_sUsername=$p_vValue;
break;
case "Password":
$this->m_sPassword=$p_vValue;
break;
case "Confirmpassword":
if($this->m_sPassword == $this->m_sConfirmpassword){
$this->m_sConfirmpassword=$p_vValue;
}
else{
$feedback = "Wachtwoorden zijn niet hetzelfde!";
}
break;
case "Firstname":
$this->m_sFirstname=$p_vValue;
break;
case "Lastname":
$this->m_sLastname=$p_vValue;
break;
case "Email":
$this->m_sEmail=$p_vValue;
break;
case "Gender":
$this->m_sGender=$p_vValue;
break;
}
}
public function Save(){
//CONSTANTS ZIJN BETER WANT DEZE KUNNEN NIET VERANDERD WORDEN
define("DB_SERVER", "localhost");
define("DB_USER", "root");
define("DB_PASS", "");
define("DB_DATABASE", "phpproject");
$conn= new mysqli(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE );
if($conn->connect_error)
{
//connectie niet gelukt
throw new Exception ("Databank niet bereikbaar");
}
else
{
$query= "INSERT INTO tblusers(Username, Password, ConfirmPassword, Firstname, Lastname, Email, Gender)
VALUES('".$this->Username."', '".$this->Password."', '".$this->Confirmpassword."', '".$this->Firstname."', '".$this->Lastname."',
'".$this->Email."','".$this->Gender."');";
}
if($conn->query($query))
{
}
else{
throw new Exception($conn->error);
}
}
}
?>
class User
{
//EIGENSCHAPPEN
private $m_sUsername;
private $m_sPassword;
private $m_sConfirmpassword;
private $m_sFirstname;
private $m_sLastname;
private $m_sEmail;
private $m_sGender;
private $m_sHost = "localhost";
private $m_sUser = "root";
private $m_sPass = "";
private $m_sDatabase = "phpproject";
//GETTER
function __get($p_sProperty)
{
switch($p_sProperty)
{
case "Username":
return $this->m_sUsername;
break;
case "Password":
return $this->m_sPassword;
break;
case "Confirmpassword":
return $this->m_sConfirmpassword;
break;
case "Firstname":
return $this->m_sFirstname;
break;
case "Lastname":
return $this->m_sLastname;
break;
case "Email":
return $this->m_sEmail;
break;
case "Gender":
return $this->m_sGender;
break;
}
}
//SETTER
function __set($p_sProperty, $p_vValue)
{
switch($p_sProperty)
{
case "Username":
$this->m_sUsername=$p_vValue;
break;
case "Password":
$this->m_sPassword=$p_vValue;
break;
case "Confirmpassword":
if($this->m_sPassword == $this->m_sConfirmpassword){
$this->m_sConfirmpassword=$p_vValue;
}
else{
$feedback = "Wachtwoorden zijn niet hetzelfde!";
}
break;
case "Firstname":
$this->m_sFirstname=$p_vValue;
break;
case "Lastname":
$this->m_sLastname=$p_vValue;
break;
case "Email":
$this->m_sEmail=$p_vValue;
break;
case "Gender":
$this->m_sGender=$p_vValue;
break;
}
}
public function Save(){
//CONSTANTS ZIJN BETER WANT DEZE KUNNEN NIET VERANDERD WORDEN
define("DB_SERVER", "localhost");
define("DB_USER", "root");
define("DB_PASS", "");
define("DB_DATABASE", "phpproject");
$conn= new mysqli(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE );
if($conn->connect_error)
{
//connectie niet gelukt
throw new Exception ("Databank niet bereikbaar");
}
else
{
$query= "INSERT INTO tblusers(Username, Password, ConfirmPassword, Firstname, Lastname, Email, Gender)
VALUES('".$this->Username."', '".$this->Password."', '".$this->Confirmpassword."', '".$this->Firstname."', '".$this->Lastname."',
'".$this->Email."','".$this->Gender."');";
}
if($conn->query($query))
{
}
else{
throw new Exception($conn->error);
}
}
}
?>
Er zijn nog geen reacties op dit bericht.