Hulp registratie script
test site. En alle hulp is zeker welkom.
<div id='full'>
</div>
<div><img src="wpimage/rebanner.png"border="0px"></div>
Dit is mijn registratie script alleen het werkt niet 100%. Ook als ik alle velden invul krijg ik Please fill in all the required fields. Je kan het zelf testen op de <div id='full'>
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
135
136
137
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
135
136
137
<?php
$form = "<form action='register.php' method='post' enctype='multipart/form-data'>
<table cellspacing='10px'>
<table>
<tr>
<td>First Name:</td>
<td><input type='text' name='firstname'><font color='red'>*</font></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type='text' name='lastname'><font color='red'>*</font></td>
<tr>
<td>Country:</td>
<td><input type='text' name='country'></td>
</tr>
<tr>
<td>Bio (Tell something about yourself):</td>
<td><textarea name='bio' cols='35' rows='5'></textarea></td>
<tr>
<td>Email:</td>
<td><input type='text' name='email'><font color='red'>*</font></td>
</tr>
</tr>
<td>Username:</td>
<td><input type='text' name='username'><font color='red'>*</font></td>
</tr>
<tr>
<td>Password:</td>
<td><input type='password' name='password'><font color='red'>*</font></td>
</tr>
<tr>
<td>Confirm Password:</td>
<td><input type='password' name='repassword'><font color='red'>*</font></td>
</tr>
<tr>
<td>Avatar:</td>
<td><input type='file' name='avatar'></td>
</tr>
<tr>
<td>Website Address:</td>
<td><input type='text' name='website'></td>
</tr>
<tr>
<td>Twitter Username:</td>
<td><input type='text' name='twitter'></td>
</tr>
<tr>
<td>Youtube Username:</td>
<td><input type='text' name='youtube'></td>
</tr>
<tr>
<td></td>
<td><input type='submit' name='submitbtn' value='Register'></td>
</table>
</form>";
if ($_POST['submitbtn']){
$firstname = strip_tags($_post['firstname']);
$lastname = strip_tags($_post['lastname']);
$country = strip_tags($_post['country']);
$bio = strip_tags($_post['bio']);
$email = strip_tags($_post['email']);
$username = strip_tags($_post['username']);
$password = strip_tags($_post['password']);
$repassword = strip_tags($_post['repassword']);
$website = strip_tags($_post['website']);
$twitter = strip_tags($_post['twitter']);
$youtube = strip_tags($_post['youtube']);
$name = $_FILES['avatar']['name'];
$type = $_FILES['avatar']['type'];
$size = $_FILES['avatar']['size'];
$tmpname = $_FILES['avatar']['tmp_name'];
$ext = substr($name, strrpos($name, '.'));
if ($firstname && $lastname && $email && $username && $password && $repassword){
if ($password == $repassword){
if (strstr($email, "@") && strstr($email, ".")) {
require("db/connect.php");
$query = mysql_query("SELECT * FROM users WHERE username='$username'");
$numrows = mysql_num_rows($query);
if ($numrows == 0) {
$query = mysql_query("SELECT * FROM users WHERE email='$email'");
$numrows = mysql_num_rows($query);
if ($numrows == 0) {
$pass = md5(md5($password));
$date = date("d F Y");
if($name){
move_uploaded_file($tmpname, "wpimage/avatar/$username.$ext");
$avatar = "$username.$ext";
}
else
$avatar = "wpimage/avatar/noimage.png";
$code = substr(md5(rand(1111111111, 9999999999)), 2, 25);
mysql_query("INSERT INTO users VALEUS('', '$firstname', '$lastname', '$country', '$email', '$username', '$pass', '$avatar', '$bio', '$website', '$twitter', '$youtube', '0', '$code', '', '0', '$date')");
$webmaster = "[email protected]";
$subject = "Activation code";
$header = "From: Jos<$webmaster>";
$message = "Hello $firstname. Welcome to our online community. Below is a activation link. Visit the link to activate your account.\n\n\n Click here to activate your account. http://mywebdomains.eu/test/activate.php?code=$code";
mail($email, $subject, $message, $headers);
echo "Check your email for the activation code. $form";
}
else
echo "That email is taken. $form";
}
else
echo "That username is taken. $form";
}
else
echo "You did not enter a valid email address. $form";
}
else
echo "Your passwords don't match. $form";
}
else
echo "Please fill in all the required fields. $form";
}
else
echo "$form";
?>
$form = "<form action='register.php' method='post' enctype='multipart/form-data'>
<table cellspacing='10px'>
<table>
<tr>
<td>First Name:</td>
<td><input type='text' name='firstname'><font color='red'>*</font></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type='text' name='lastname'><font color='red'>*</font></td>
<tr>
<td>Country:</td>
<td><input type='text' name='country'></td>
</tr>
<tr>
<td>Bio (Tell something about yourself):</td>
<td><textarea name='bio' cols='35' rows='5'></textarea></td>
<tr>
<td>Email:</td>
<td><input type='text' name='email'><font color='red'>*</font></td>
</tr>
</tr>
<td>Username:</td>
<td><input type='text' name='username'><font color='red'>*</font></td>
</tr>
<tr>
<td>Password:</td>
<td><input type='password' name='password'><font color='red'>*</font></td>
</tr>
<tr>
<td>Confirm Password:</td>
<td><input type='password' name='repassword'><font color='red'>*</font></td>
</tr>
<tr>
<td>Avatar:</td>
<td><input type='file' name='avatar'></td>
</tr>
<tr>
<td>Website Address:</td>
<td><input type='text' name='website'></td>
</tr>
<tr>
<td>Twitter Username:</td>
<td><input type='text' name='twitter'></td>
</tr>
<tr>
<td>Youtube Username:</td>
<td><input type='text' name='youtube'></td>
</tr>
<tr>
<td></td>
<td><input type='submit' name='submitbtn' value='Register'></td>
</table>
</form>";
if ($_POST['submitbtn']){
$firstname = strip_tags($_post['firstname']);
$lastname = strip_tags($_post['lastname']);
$country = strip_tags($_post['country']);
$bio = strip_tags($_post['bio']);
$email = strip_tags($_post['email']);
$username = strip_tags($_post['username']);
$password = strip_tags($_post['password']);
$repassword = strip_tags($_post['repassword']);
$website = strip_tags($_post['website']);
$twitter = strip_tags($_post['twitter']);
$youtube = strip_tags($_post['youtube']);
$name = $_FILES['avatar']['name'];
$type = $_FILES['avatar']['type'];
$size = $_FILES['avatar']['size'];
$tmpname = $_FILES['avatar']['tmp_name'];
$ext = substr($name, strrpos($name, '.'));
if ($firstname && $lastname && $email && $username && $password && $repassword){
if ($password == $repassword){
if (strstr($email, "@") && strstr($email, ".")) {
require("db/connect.php");
$query = mysql_query("SELECT * FROM users WHERE username='$username'");
$numrows = mysql_num_rows($query);
if ($numrows == 0) {
$query = mysql_query("SELECT * FROM users WHERE email='$email'");
$numrows = mysql_num_rows($query);
if ($numrows == 0) {
$pass = md5(md5($password));
$date = date("d F Y");
if($name){
move_uploaded_file($tmpname, "wpimage/avatar/$username.$ext");
$avatar = "$username.$ext";
}
else
$avatar = "wpimage/avatar/noimage.png";
$code = substr(md5(rand(1111111111, 9999999999)), 2, 25);
mysql_query("INSERT INTO users VALEUS('', '$firstname', '$lastname', '$country', '$email', '$username', '$pass', '$avatar', '$bio', '$website', '$twitter', '$youtube', '0', '$code', '', '0', '$date')");
$webmaster = "[email protected]";
$subject = "Activation code";
$header = "From: Jos<$webmaster>";
$message = "Hello $firstname. Welcome to our online community. Below is a activation link. Visit the link to activate your account.\n\n\n Click here to activate your account. http://mywebdomains.eu/test/activate.php?code=$code";
mail($email, $subject, $message, $headers);
echo "Check your email for the activation code. $form";
}
else
echo "That email is taken. $form";
}
else
echo "That username is taken. $form";
}
else
echo "You did not enter a valid email address. $form";
}
else
echo "Your passwords don't match. $form";
}
else
echo "Please fill in all the required fields. $form";
}
else
echo "$form";
?>
</div>
<div><img src="wpimage/rebanner.png"border="0px"></div>
Gewijzigd op 07/11/2010 16:37:16 door Jos Savelberg
Het is $_POST, en geen $_post
Aar anoniem op 07/11/2010 16:39:05:
Het is $_POST, en geen $_post
Heel erg bedankt, het werkt :D
raar dat in dreamweaver allebei worden goed geteld voor het script.
Dreamweaver is gewoon kut....
De query klopt volgens mij wel. Bij de oplopende velden hoef je geen waarde mee te geven.
maak een mooie foutafhandeling voor je query dan zie je wat er mis is.
PHP jasper op 07/11/2010 17:57:55:
maak een mooie foutafhandeling voor je query dan zie je wat er mis is.
Hoe maak ik een mooie foutafhandeling voor mijn query?
Heb een fout melding als ik users (naam van de tabel) tussen aanhalingstekens zet. De error is Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in ../../register.php on line 87, 91 and in activate on line 38
Gewijzigd op 07/11/2010 18:11:00 door Jos Savelberg
Code (php)
1
2
3
4
5
6
2
3
4
5
6
$result = mysql_query("INSERT INTO users VALEUS('', '$firstname', '$lastname', '$country', '$email', '$username', '$pass', '$avatar', '$bio', '$website', '$twitter', '$youtube', '0', '$code', '', '0', '$date')");
if($result) {
// hier alle acties die plaatsenvinden als de query gelukt is:
} else {
// niet gelukt!
echo "Fout: ".mysql_error();
if($result) {
// hier alle acties die plaatsenvinden als de query gelukt is:
} else {
// niet gelukt!
echo "Fout: ".mysql_error();
http://www.netbeans.org/.
Hier kan je veel beter in programmeren en worden fouten sneller aangegeven. Misschien ook een aanrader voor jou. Het programma is overgens ook nog gratis.
@jos ik ben ook begonnen met Dreamweaver. In het begin vond ik het handig aangezien je direct de html kon zien. Maar na een tijdje had ik dat niet meer nodig en ben ik overgestapt op Netbeans Hier kan je veel beter in programmeren en worden fouten sneller aangegeven. Misschien ook een aanrader voor jou. Het programma is overgens ook nog gratis.
Code (php)
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
<?php
$query = "INSERT INTO users VALUES('', '".$firstname."', '".$lastname."', '".$country."', '".$email."', '".$username."', '".$pass."', '".$avatar."', '".$bio."', '".$website."', '".$twitter."', '".$youtube."', '".0."', '".$code."', '', ".'0."', '".$date."'";
$result = mysql_query($query);
if(!$result) {
echo "Fout: ".mysql_error($result)."<br />".$query;
}
else {
//als het gelukt is
}
?>
$query = "INSERT INTO users VALUES('', '".$firstname."', '".$lastname."', '".$country."', '".$email."', '".$username."', '".$pass."', '".$avatar."', '".$bio."', '".$website."', '".$twitter."', '".$youtube."', '".0."', '".$code."', '', ".'0."', '".$date."'";
$result = mysql_query($query);
if(!$result) {
echo "Fout: ".mysql_error($result)."<br />".$query;
}
else {
//als het gelukt is
}
?>
Edit:
Zoals je ziet heb ik de variable buiten de quote's gezet. Dit is beter
Gewijzigd op 07/11/2010 18:20:08 door Wouter J
Aar anoniem op 07/11/2010 18:13:42:
Code (php)
1
2
3
4
5
6
2
3
4
5
6
$result = mysql_query("INSERT INTO users VALEUS('', '$firstname', '$lastname', '$country', '$email', '$username', '$pass', '$avatar', '$bio', '$website', '$twitter', '$youtube', '0', '$code', '', '0', '$date')");
if($result) {
// hier alle acties die plaatsenvinden als de query gelukt is:
} else {
// niet gelukt!
echo "Fout: ".mysql_error();
if($result) {
// hier alle acties die plaatsenvinden als de query gelukt is:
} else {
// niet gelukt!
echo "Fout: ".mysql_error();
Bedankt, Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/onbvezxr/domains/mywebdomains.eu/public_html/test/register.php on line 87
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/onbvezxr/domains/mywebdomains.eu/public_html/test/register.php on line 91
en daaronder staat "fout: "
Gewijzigd op 07/11/2010 18:27:33 door Jos Savelberg
Aar anoniem op 07/11/2010 18:29:41:
en al gekeken naar het commentaar?
Hoe heb je deze code dan ingebouwd?
Hoe heb je deze code dan ingebouwd?
de code $result = mysql_query($query);
if(!$result) {
echo "Fout: ".mysql_error($result)."<br />".$query;
}
else {
//als het gelukt is
}
?>
heb ik onder de aanvraag van de query geplakt, Zodat er hopelijk een echo zou komen. Nu kreeg ik alleen die 2 errors. Ik ben begonnen met het downloaden van NetBeans misschien dat ik daarmee beter kan werken. Ik kreeg daar wel "fout: " te zien, maar niet echt het resultaat waarop ik hoopte misschien heb ik wel iets fouts gedaan.
Gewijzigd op 07/11/2010 18:36:40 door Jos Savelberg
ook de manier van opbouw bij de insert?
Fout:
Deze fout krijg ik als ik de "controle" doe
op line 109 staat
if(!$result) {
echo "Fout: ".mysql_error($result)."<br />".$query;
}
Toevoeging op 07/11/2010 19:01:30:
Vincent Huisman op 07/11/2010 18:55:46:
ook de manier van opbouw bij de insert?
Bedoel je met rij de tabel in mysql of echt 1 voor 1 alle Velden mee?
Gewijzigd op 07/11/2010 19:01:54 door Jos Savelberg
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
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
<?php
/******************* Zet dit bovenaan je script *******************/
// errors
ini_set('display_errors',1);
error_reporting(E_ALL | E_STRICT);
// sql debug
define('DEBUG_MODE',true);
function showSQLError($sql,$error) {
echo '<pre>Error: '.$error.'<br />'.$sql.'</pre>';
}
/******************* start script *******************/
// dit is je query ->
$sql = "INSERT INTO users
VALUES('', '".$firstname."', '".$lastname."', '".$country."', '".$email."', '".$username."', '".$pass."', '".$avatar."', '".$bio."', '".$website."', '".$twitter."', '".$youtube."', '0', '".$code."', '', '0', '".$date."')
";
if (($result = mysql_query($sql)) === false) {
// foutafhandeling
echo 'Fout met database.';
if (DEBUG_MODE) {
showSQLError($sql,mysql_error());
}
}
else {
// je query is gelukt
}
?>
/******************* Zet dit bovenaan je script *******************/
// errors
ini_set('display_errors',1);
error_reporting(E_ALL | E_STRICT);
// sql debug
define('DEBUG_MODE',true);
function showSQLError($sql,$error) {
echo '<pre>Error: '.$error.'<br />'.$sql.'</pre>';
}
/******************* start script *******************/
// dit is je query ->
$sql = "INSERT INTO users
VALUES('', '".$firstname."', '".$lastname."', '".$country."', '".$email."', '".$username."', '".$pass."', '".$avatar."', '".$bio."', '".$website."', '".$twitter."', '".$youtube."', '0', '".$code."', '', '0', '".$date."')
";
if (($result = mysql_query($sql)) === false) {
// foutafhandeling
echo 'Fout met database.';
if (DEBUG_MODE) {
showSQLError($sql,mysql_error());
}
}
else {
// je query is gelukt
}
?>
Notice: Undefined variable: firstname in /home/onbvezxr/domains/mywebdomains.eu/public_html/test/register.php on line 22
Notice: Undefined variable: lastname in /home/onbvezxr/domains/mywebdomains.eu/public_html/test/register.php on line 22
Notice: Undefined variable: country in /home/onbvezxr/domains/mywebdomains.eu/public_html/test/register.php on line 22
Notice: Undefined variable: email in /home/onbvezxr/domains/mywebdomains.eu/public_html/test/register.php on line 22
Notice: Undefined variable: username in /home/onbvezxr/domains/mywebdomains.eu/public_html/test/register.php on line 22
Notice: Undefined variable: pass in /home/onbvezxr/domains/mywebdomains.eu/public_html/test/register.php on line 22
Notice: Undefined variable: avatar in /home/onbvezxr/domains/mywebdomains.eu/public_html/test/register.php on line 22
Notice: Undefined variable: bio in /home/onbvezxr/domains/mywebdomains.eu/public_html/test/register.php on line 22
Notice: Undefined variable: website in /home/onbvezxr/domains/mywebdomains.eu/public_html/test/register.php on line 22
Notice: Undefined variable: twitter in /home/onbvezxr/domains/mywebdomains.eu/public_html/test/register.php on line 22
Notice: Undefined variable: youtube in /home/onbvezxr/domains/mywebdomains.eu/public_html/test/register.php on line 22
Notice: Undefined variable: code in /home/onbvezxr/domains/mywebdomains.eu/public_html/test/register.php on line 22
Notice: Undefined variable: date in /home/onbvezxr/domains/mywebdomains.eu/public_html/test/register.php on line 22
Warning: mysql_query() [function.mysql-query]: Access denied for user 'apache'@'localhost' (using password: NO) in /home/onbvezxr/domains/mywebdomains.eu/public_html/test/register.php on line 25
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/onbvezxr/domains/mywebdomains.eu/public_html/test/register.php on line 25
Fout met database.
Error: Access denied for user 'apache'@'localhost' (using password: NO)INSERT INTO users
VALUES('', '', '', '', '', '', '', '', '', '', '', '', '0', '', '', '0', '')
PHP jasper op 07/11/2010 19:04:31:
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
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
<?php
/******************* Zet dit bovenaan je script *******************/
// errors
ini_set('display_errors',1);
error_reporting(E_ALL | E_STRICT);
// sql debug
define('DEBUG_MODE',true);
function showSQLError($sql,$error) {
echo '<pre>Error: '.$error.'<br />'.$sql.'</pre>';
}
/******************* start script *******************/
// dit is je query ->
$sql = "INSERT INTO users
VALUES('', '".$firstname."', '".$lastname."', '".$country."', '".$email."', '".$username."', '".$pass."', '".$avatar."', '".$bio."', '".$website."', '".$twitter."', '".$youtube."', '0', '".$code."', '', '0', '".$date."')
";
if (($result = mysql_query($sql)) === false) {
// foutafhandeling
echo 'Fout met database.';
if (DEBUG_MODE) {
showSQLError($sql,mysql_error());
}
}
else {
// je query is gelukt
}
?>
/******************* Zet dit bovenaan je script *******************/
// errors
ini_set('display_errors',1);
error_reporting(E_ALL | E_STRICT);
// sql debug
define('DEBUG_MODE',true);
function showSQLError($sql,$error) {
echo '<pre>Error: '.$error.'<br />'.$sql.'</pre>';
}
/******************* start script *******************/
// dit is je query ->
$sql = "INSERT INTO users
VALUES('', '".$firstname."', '".$lastname."', '".$country."', '".$email."', '".$username."', '".$pass."', '".$avatar."', '".$bio."', '".$website."', '".$twitter."', '".$youtube."', '0', '".$code."', '', '0', '".$date."')
";
if (($result = mysql_query($sql)) === false) {
// foutafhandeling
echo 'Fout met database.';
if (DEBUG_MODE) {
showSQLError($sql,mysql_error());
}
}
else {
// je query is gelukt
}
?>