mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\register.php o
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\register.php on line 74
Heb al geprobeerd mysql_num_rows te vervangen maar dat lukt niet.
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
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
<?
session_start();
?>
<font face=verdana size=1>
<?
if($_SESSION['login'] == "true"){
print " You have allready an account.";//because your logged in stupid
}
include('connect.inc.php');
if(!isset($_REQUEST['submit'])){
?>
<form method=post acion=""<? $_SERVER['PHP_SELF'] ?>"">
<table>
<tr>
<td>
<font face=verdana size=1>Username:
</td>
<td>
<input type="text" name="name" maxlength="15">
</td>
</tr>
<tr>
<td>
<font face=verdana size=1>Password:
</td>
<td>
<input type="password" name="pass1">
</td>
</tr>
<tr>
<td>
<font face=verdana size=1>Confirm:
</td>
<td>
<input type="password" name="pass2">
</td>
</tr>
<tr>
<td>
<input type="submit" value=submit name="submit">
</td>
<td>
<input type="reset">
</td>
</tr>
</table>
</form>
<?php
}else{
//request everything
$dead = "false";//We make 'dead' if some fields are not filled in don't check for pass and name in db.
$message = "<font face=verdana size=1>Pleas fill in all fields correctly:<br>";
$username = $_POST['name'];
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];
$ip = $_SERVER['REMOTE_ADDR'];
$status = "1";//1 member, 2,co-admin 3, admin
//begin search for errors
if(strlen($username) <= 1 or strlen($username) >=15){
$dead = "true";
$message .= "Username (2-14)<br>";
}
if(strlen($pass1) < 6 or strlen($pass1) > 20 or $pass1 !== $pass2) {
$dead = "true";
$message .= "Password (6-20) or passwords does not match";
}
if($dead = "false"){
$username = strtolower(trim(strip_tags($username)));
$pass1 = trim($pass1);
$pass1 = md5($pass1);
$query = mysql_query("SELECT * FROM members WHERE username ='$username'");
$aantalrijen = mysql_num_rows($query);
if($aantalrijen == 1){
print "<font face=verdana size=1>Sorry, your username exists allready.";
}
else{
$query1 = "INSERT INTO members(username, password, ip, status) VALUES ('$username','$pass1', '$ip','$status')";
if(mysql_query($query1)){
print "<font face=verdana size=1>Well donne your now a member of the RTD group.<br><a href=login.php>Login</a>";
}
}
}
elseif($dead == "true"){
print $message;
}
}
?>
session_start();
?>
<font face=verdana size=1>
<?
if($_SESSION['login'] == "true"){
print " You have allready an account.";//because your logged in stupid
}
include('connect.inc.php');
if(!isset($_REQUEST['submit'])){
?>
<form method=post acion=""<? $_SERVER['PHP_SELF'] ?>"">
<table>
<tr>
<td>
<font face=verdana size=1>Username:
</td>
<td>
<input type="text" name="name" maxlength="15">
</td>
</tr>
<tr>
<td>
<font face=verdana size=1>Password:
</td>
<td>
<input type="password" name="pass1">
</td>
</tr>
<tr>
<td>
<font face=verdana size=1>Confirm:
</td>
<td>
<input type="password" name="pass2">
</td>
</tr>
<tr>
<td>
<input type="submit" value=submit name="submit">
</td>
<td>
<input type="reset">
</td>
</tr>
</table>
</form>
<?php
}else{
//request everything
$dead = "false";//We make 'dead' if some fields are not filled in don't check for pass and name in db.
$message = "<font face=verdana size=1>Pleas fill in all fields correctly:<br>";
$username = $_POST['name'];
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];
$ip = $_SERVER['REMOTE_ADDR'];
$status = "1";//1 member, 2,co-admin 3, admin
//begin search for errors
if(strlen($username) <= 1 or strlen($username) >=15){
$dead = "true";
$message .= "Username (2-14)<br>";
}
if(strlen($pass1) < 6 or strlen($pass1) > 20 or $pass1 !== $pass2) {
$dead = "true";
$message .= "Password (6-20) or passwords does not match";
}
if($dead = "false"){
$username = strtolower(trim(strip_tags($username)));
$pass1 = trim($pass1);
$pass1 = md5($pass1);
$query = mysql_query("SELECT * FROM members WHERE username ='$username'");
$aantalrijen = mysql_num_rows($query);
if($aantalrijen == 1){
print "<font face=verdana size=1>Sorry, your username exists allready.";
}
else{
$query1 = "INSERT INTO members(username, password, ip, status) VALUES ('$username','$pass1', '$ip','$status')";
if(mysql_query($query1)){
print "<font face=verdana size=1>Well donne your now a member of the RTD group.<br><a href=login.php>Login</a>";
}
}
}
elseif($dead == "true"){
print $message;
}
}
?>
Code (php)
1
2
3
2
3
<?php
$query = mysql_query("SELECT * FROM members WHERE username ='$username'") or die (mysql_error());
?>
$query = mysql_query("SELECT * FROM members WHERE username ='$username'") or die (mysql_error());
?>
Unknown column 'username' in 'where clause'
Moet het niet zijn
Code (php)
1
2
3
2
3
<?php
$query = mysql_query("SELECT * FROM members WHERE username =$username") or die (mysql_error());
?>
$query = mysql_query("SELECT * FROM members WHERE username =$username") or die (mysql_error());
?>
Gewijzigd op 06/01/2012 10:09:48 door Bas van de Steeg
Nee het veld username bestaat niet in je tabel members dus moet je even naar je tabel structuur kijken
Probeer ook eens een username met enkele quotes erin te registreren. Zie SQL-injectie waarom dit fout gaat, en wat je eraan kan doen.
Dat was de error.
Username moest Users zijn.
foutafhandeling. Zo kan je deze fouten zelf opsporen en oplossen.
zorg steeds voor een PHP Jasper op 06/01/2012 11:04:23:
zorg steeds voor een foutafhandeling. Zo kan je deze fouten zelf opsporen en oplossen.
Heb ik net toegevoegd :)
Super, pas dit telkens toe als je een query schrijft zo kan je onmiddellijk zien wat er mis loopt. Dat bespaart je tijd, stress en last.