Inloggen
Ik het zo goed als mogelijk aangepast maar krijg de volgende foutmelding:
De query is niet gelukt: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE username=' ed' AND password=' abc '' at line 1
Bijgaand de 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
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
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
<!DOCTYPE html>
<html>
<head>
<title>Inloggen</title>
</head>
<body>
<center>
<br>
<h1>Inloggen</h1>
<br>
<div style= "background-color: grey; width: 1000px">
<br>
<br>
<form action =# method="POST">
<div>
<label>Wachtwoord</label>
<input type="text" name="username" required>
</div>
<br>
<br>
<div>
<label>Password</label>
<input type="password" name="password" required>
</div>
<br>
<br>
<div>
<input type="submit" value="Login">
</div>
</form>
<br>
</div>
</center>
<?php
$host = "localhost";
$user = "root";
$password ="usbw";
$db = "login";
$data = mysqli_connect($host, $user, $password, $db);
if($data==false)
{
die ("Connection error");
}
if($_SERVER ["REQUEST_METHOD"]=="POST")
{
$username = $_POST["username"];
$password = $_POST["password"];
$sql = "SELECT * FROM login WHERE username= ' ".$username. "' AND password= ' ".$password. " ' WHERE username=' ed' AND password=' abc '";
$result = mysqli_query($data, $sql);
}
if( $result = mysqli_query($data,$sql) )
{
$row = mysqli_fetch_array($result);
if( $row["usertype"]=="user" )
{
echo "user";
}
elseif($row["usertype"]=="admin")
{
echo "admin";
}
else
{
echo "username or password incorrect";
}
} else {
echo "De query is niet gelukt: ".mysqli_error($data);
}
?>
<html>
<head>
<title>Inloggen</title>
</head>
<body>
<center>
<br>
<h1>Inloggen</h1>
<br>
<div style= "background-color: grey; width: 1000px">
<br>
<br>
<form action =# method="POST">
<div>
<label>Wachtwoord</label>
<input type="text" name="username" required>
</div>
<br>
<br>
<div>
<label>Password</label>
<input type="password" name="password" required>
</div>
<br>
<br>
<div>
<input type="submit" value="Login">
</div>
</form>
<br>
</div>
</center>
<?php
$host = "localhost";
$user = "root";
$password ="usbw";
$db = "login";
$data = mysqli_connect($host, $user, $password, $db);
if($data==false)
{
die ("Connection error");
}
if($_SERVER ["REQUEST_METHOD"]=="POST")
{
$username = $_POST["username"];
$password = $_POST["password"];
$sql = "SELECT * FROM login WHERE username= ' ".$username. "' AND password= ' ".$password. " ' WHERE username=' ed' AND password=' abc '";
$result = mysqli_query($data, $sql);
}
if( $result = mysqli_query($data,$sql) )
{
$row = mysqli_fetch_array($result);
if( $row["usertype"]=="user" )
{
echo "user";
}
elseif($row["usertype"]=="admin")
{
echo "admin";
}
else
{
echo "username or password incorrect";
}
} else {
echo "De query is niet gelukt: ".mysqli_error($data);
}
?>
zover ik weet gebruik versie 5 van ik weet of dat daar al mis gaat, maar mijn inziens niet. Wat gaat er nu mis?
Groetjes
Ed
Wat is volgens jouw het nut om eerst te kijken naar je invoer, en daarna opeens hardcoded te controleren op 'ed' en 'abc'? Dit lijkt mij een gevalletje van een foute copy-paste?
Sowieso kan je nooit WHERE AND WHERE AND als volgorde gebruiken.
Bijna alle fouten weggewerkt maar deze blijft over:
username or password incorrect
Wat is nog het probleem?
Toevoeging op 05/11/2021 16:39:28:
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
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
<!DOCTYPE html>
<html>
<head>
<title>Inloggen</title>
</head>
<body>
<center>
<br>
<h1>Inloggen</h1>
<br>
<div style= "background-color: grey; width: 1000px">
<br>
<br>
<form action =# method="POST">
<div>
<label>Wachtwoord</label>
<input type="text" name="username" required>
</div>
<br>
<br>
<div>
<label>Password</label>
<input type="password" name="password" required>
</div>
<br>
<br>
<div>
<input type="submit" value="Login">
</div>
</form>
<br>
</div>
</center>
<?php
$host = "localhost";
$user = "root";
$password ="usbw";
$db = "login";
$data = mysqli_connect($host, $user, $password, $db);
if($data==false)
{
die ("Connection error");
}
if($_SERVER ["REQUEST_METHOD"]=="POST")
{
$username = $_POST["username"];
$password = $_POST["password"];
$sql = "SELECT * FROM user WHERE username = ' ".$username. "' AND password = ' ".$password. " '";
$result = mysqli_query($data, $sql);
}
if( $result = mysqli_query($data,$sql) )
{
$row = mysqli_fetch_array($result);
if( $row["usertype"]=="user" )
{
echo "user";
}
elseif($row["usertype"]=="admin")
{
echo "admin";
}
else
{
echo "username or password incorrect";
}
} else
{
echo "De query is niet gelukt: ".mysqli_error($data);
}
?>
<html>
<head>
<title>Inloggen</title>
</head>
<body>
<center>
<br>
<h1>Inloggen</h1>
<br>
<div style= "background-color: grey; width: 1000px">
<br>
<br>
<form action =# method="POST">
<div>
<label>Wachtwoord</label>
<input type="text" name="username" required>
</div>
<br>
<br>
<div>
<label>Password</label>
<input type="password" name="password" required>
</div>
<br>
<br>
<div>
<input type="submit" value="Login">
</div>
</form>
<br>
</div>
</center>
<?php
$host = "localhost";
$user = "root";
$password ="usbw";
$db = "login";
$data = mysqli_connect($host, $user, $password, $db);
if($data==false)
{
die ("Connection error");
}
if($_SERVER ["REQUEST_METHOD"]=="POST")
{
$username = $_POST["username"];
$password = $_POST["password"];
$sql = "SELECT * FROM user WHERE username = ' ".$username. "' AND password = ' ".$password. " '";
$result = mysqli_query($data, $sql);
}
if( $result = mysqli_query($data,$sql) )
{
$row = mysqli_fetch_array($result);
if( $row["usertype"]=="user" )
{
echo "user";
}
elseif($row["usertype"]=="admin")
{
echo "admin";
}
else
{
echo "username or password incorrect";
}
} else
{
echo "De query is niet gelukt: ".mysqli_error($data);
}
?>
het geval met spaties heb ik even als commentaar gezet
Hoe los ik het probleem nu op??
ik heb als gbn user gebruikt en als wachtwoord 1234
Dat doe ik niet!
ik vul in user en 1234!!
Quote:
zoekt MySQL dus naar [spatie]user.
en voor password vraag jij aan de database naar [spatie]1234[spatie]
een beeetje begrijpend lezen is misschien wel handig....
Maar in de query staan er SPATIES VOOR EN ACHTER.
Als je goed kijkt kan je ze zien.
Code (php)
1
$sql = "SELECT * FROM user WHERE username = ' ".$username. "' AND password = ' ".$password. " '";
Toevoeging op 05/11/2021 17:27:16:
HBO denknivo
Oeps sorry niet gezien maar ik kom nu bij user uit!! Yippie
Volgende stappen:
- Beveiliging tegen SQL injection
- Wachtwoorden hashen om ze onleesbaar te maken, dmv. password_hash en password_verify
- Goede controle of een password of gebruikersnaam fout is. Nu kijk je naar 'usertype', en niet naar het aantal rijen die je ophaalt met je select-query (moet 1 zijn als de gebruiker bestaat, en 0 als die niet bestaat. Wachtwoorden kan controleren met password_verify().
Notice: Undefined variable: sql in C:\USB WebServer\root\Website\login2.php on line 67
Warning: mysqli_query(): Empty query in C:\USB WebServer\root\Website\login2.php on line 67
De query is niet gelukt:
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
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
<!DOCTYPE html>
<html>
<head>
<title>Inloggen</title>
</head>
<body>
<center>
<br>
<h1>Inloggen</h1>
<br>
<div style= "background-color: grey; width: 1000px">
<br>
<br>
<form action =# method="POST">
<div>
<label>Wachtwoord</label>
<input type="text" name="username" required>
</div>
<br>
<br>
<div>
<label>Password</label>
<input type="password" name="password" required>
</div>
<br>
<br>
<div>
<input type="submit" value="Login">
</div>
</form>
<br>
</div>
</center>
</body>
</html>
<?php
$host = "localhost";
$user = "root";
$password ="usbw";
$db = "login";
$data = mysqli_connect($host, $user, $password, $db);
if($data==false)
{
die ("Connection error");
}
if($_SERVER ["REQUEST_METHOD"]=="POST")
{
$username = $_POST["username"];
$password = $_POST["password"];
$sql = "SELECT * FROM user WHERE username = '".$username."' AND password = '".$password."'";
$result = mysqli_query($data,$sql);
}
if( $result = mysqli_query($data,$sql) )
{
$row = mysqli_fetch_array($result);
if( $row["usertype"]=="user" )
{
header ("location:userhome.php");
}
elseif($row["usertype"]=="admin")
{
header ("location:adminhome.php");
}
else
{
echo "username or password incorrect";
}
} else
{
echo "De query is niet gelukt: ".mysqli_error($data);
}
?>
<html>
<head>
<title>Inloggen</title>
</head>
<body>
<center>
<br>
<h1>Inloggen</h1>
<br>
<div style= "background-color: grey; width: 1000px">
<br>
<br>
<form action =# method="POST">
<div>
<label>Wachtwoord</label>
<input type="text" name="username" required>
</div>
<br>
<br>
<div>
<label>Password</label>
<input type="password" name="password" required>
</div>
<br>
<br>
<div>
<input type="submit" value="Login">
</div>
</form>
<br>
</div>
</center>
</body>
</html>
<?php
$host = "localhost";
$user = "root";
$password ="usbw";
$db = "login";
$data = mysqli_connect($host, $user, $password, $db);
if($data==false)
{
die ("Connection error");
}
if($_SERVER ["REQUEST_METHOD"]=="POST")
{
$username = $_POST["username"];
$password = $_POST["password"];
$sql = "SELECT * FROM user WHERE username = '".$username."' AND password = '".$password."'";
$result = mysqli_query($data,$sql);
}
if( $result = mysqli_query($data,$sql) )
{
$row = mysqli_fetch_array($result);
if( $row["usertype"]=="user" )
{
header ("location:userhome.php");
}
elseif($row["usertype"]=="admin")
{
header ("location:adminhome.php");
}
else
{
echo "username or password incorrect";
}
} else
{
echo "De query is niet gelukt: ".mysqli_error($data);
}
?>
Ik ben weer vooraan begonnen. Het uploaden van de bestanden gaat nu wel, maar ik kan nog steeds niet in de database zetten. En daar ging het om,want ik wil ze weer kunnen uitlezen. Wie kan me helpen?
Wat doe ik in deze regel mis?
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
54
55
56
57
58
59
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
<!DOCTYPE html>
<html>
<head>
<title>File Upload</title>
</head>
<body>
<form method="post" enctype="multipart/form-data">
<label>Titel</label>
<input type="text" name="title">
<label>File Upload</label>
<input type="File" name="file">
<input type="submit" name="submit">
</form>
</body>
</html>
<?php
//verbinding maken met de database
//$conn = mysqli_connect('localhost', 'root', 'usbw', 'imageupload');// de laatste is de naam van de dadatabase
require_once "connection.php";
if (isset($_POST["submit"]))
{
//file title
$title = $_POST["title"];
//file name
$name = $_FILES["file"]["name"];
//temporary file name to store file
$tname = $_FILES["file"]["tmp_name"];
//upload directory pad
$uploads_dir = 'images';
//Kopieer de dabestanden
move_uploaded_file($tname, $uploads_dir.'/'.$name);
//SQL om de de documenten in de db te zetten
$sql = "INSERT INTO imageupload(title, image) VALUES('$title','$name')";
if(mysqli_query($conn, $sql))
{
echo "File Sucessfully uploaded";
}
else{
echo "Error";
}
}
[/code]
<html>
<head>
<title>File Upload</title>
</head>
<body>
<form method="post" enctype="multipart/form-data">
<label>Titel</label>
<input type="text" name="title">
<label>File Upload</label>
<input type="File" name="file">
<input type="submit" name="submit">
</form>
</body>
</html>
<?php
//verbinding maken met de database
//$conn = mysqli_connect('localhost', 'root', 'usbw', 'imageupload');// de laatste is de naam van de dadatabase
require_once "connection.php";
if (isset($_POST["submit"]))
{
//file title
$title = $_POST["title"];
//file name
$name = $_FILES["file"]["name"];
//temporary file name to store file
$tname = $_FILES["file"]["tmp_name"];
//upload directory pad
$uploads_dir = 'images';
//Kopieer de dabestanden
move_uploaded_file($tname, $uploads_dir.'/'.$name);
//SQL om de de documenten in de db te zetten
$sql = "INSERT INTO imageupload(title, image) VALUES('$title','$name')";
if(mysqli_query($conn, $sql))
{
echo "File Sucessfully uploaded";
}
else{
echo "Error";
}
}
[/code]
Plots gaat het over uploaden van een bestand.
Hier dus :
https://www.phphulp.nl/php/forum/topic/pdf-in-beeld-brengen/104348/
En sowieso raad ik aan om eerst te kijken of de upload gelukt is, en daarna de query uit te voeren.
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
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
<html>
<body>
<a href ="index.php"></a>
<?php
require_once "connection.php";
$sql = "SELECT * FROM imageupload ORDER BY id DESC";
$res = mysqli_query($conn, $sql);
//print_r ($res);
if(mysqli_num_rows($res)> 0)
{
while($images = mysqli_fetch_assoc($res))
{
// print_r ($images);
?>
<div class = "alb">
<img src = "images/<?php echo $images['image']; ?>">
<?php echo $images['title']; ?>
</div>
<?php }
}
?>
</body>
<html>
<body>
<a href ="index.php"></a>
<?php
require_once "connection.php";
$sql = "SELECT * FROM imageupload ORDER BY id DESC";
$res = mysqli_query($conn, $sql);
//print_r ($res);
if(mysqli_num_rows($res)> 0)
{
while($images = mysqli_fetch_assoc($res))
{
// print_r ($images);
?>
<div class = "alb">
<img src = "images/<?php echo $images['image']; ?>">
<?php echo $images['title']; ?>
</div>
<?php }
}
?>
</body>
<html>
De werkende code!