Hulp met fout: Undefined Variable: _SESSION en Call To Undefined Method PDO::fetch()
Tijdens het volgen van een blog tutorial liep ik tegen een probleem aan. Vervolgens leek het of ik het probleem had opgelost door een paar aanpassingen te doen, maar helaas.. zonder resultaat.
Ik krijg na het inloggen als admin de fout: ]Undefined Variable: _SESSION en Call To Undefined Method PDO::fetch()
Het gaat om de code hieronder.
Alvast heel erg bedankt! :)
Index.php
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?php
include_once "../blog/connect.php";
include_once "../blog/functie.php";
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Dashboard I Admin Panel</title>
<link rel="stylesheet" href="css/layout.css" type="text/css" media="screen" />
<!--[if lt IE 9]>
<link rel="stylesheet" href="css/ie.css" type="text/css" media="screen" />
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script src="js/jquery-1.5.2.min.js" type="text/javascript"></script>
<script src="js/hideshow.js" type="text/javascript"></script>
<script src="js/jquery.tablesorter.min.js" type="text/javascript"></script>
<script type="text/javascript" src="js/jquery.equalHeight.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$(".tablesorter").tablesorter();
}
);
$(document).ready(function() {
//When page loads...
$(".tab_content").hide(); //Hide all content
$("ul.tabs li:first").addClass("active").show(); //Activate first tab
$(".tab_content:first").show(); //Show first tab content
//On Click Event
$("ul.tabs li").click(function() {
$("ul.tabs li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$(".tab_content").hide(); //Hide all tab content
var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active ID content
return false;
});
});
</script>
<script type="text/javascript">
$(function(){
$('.column').equalHeight();
});
</script>
</head>
<body>
<?php
if(session("login") && session("uye_rutbe") == 1){
require_once "inc/default.php";
}else{
}
if ($_POST){
$kadi= p("kadi");
$sifre = md5(p("sifre"));
if (!$kadi || !$sifre){
echo "kullanıcı adı sifre bos bırakılamaz";
}
else{
$row = $connect->query("SELECT * FROM uyeler WHERE uye_kadi = '$kadi' && uye_sifre = '$sifre'");
$row = $connect->fetch(PDO::FETCH_ASSOC);
if ( $row["uye_id"])
{
$session = array(
"giris_yap" => true,
"uye_id" => $row["uye_id"],
"uye_kadi" => $row["uye_kadi"],
"uye_rutbe" => $row["uye_rutbe"]
);
session_olustur($session);
header("Refresh:0;");
} else {
echo "<font color='red'>Böyle Bir Yönetici Yoktur.</font>";
}
}
}
?>
<div id="giris_yap">
<form action="" method="post">
<table cellpadding="0" cellspacing="0">
<tr>
<td>Gebruikersnaam:</td>
<td><input type="text" name="kadi" /></td>
</tr>
<tr>
<td>Wachtwoord:</td>
<td><input type="password" name="sifre" /></td>
</tr>
<tr>
<td></td>
<td><button type="submit">Inloggen</button></td>
</tr>
</table>
</form>
</div>
</body>
</html>
functie.php
<?php
function p($par, $st =false){
if($st){
return htmlspecialchars(trim($_POST[$par]));
}else{
return trim( $_POST[$par]);
}
}
function g($par){
return strip_tag(trim($_GET[$par]));
}
function kisalt($par,$uzunluk = 50){
if(strlen($par) > $uzunluk){
$par=mb_substr($par,0,$uzunluk,"UTF-8").". .";
}
return $par;
}
function go($par, $time = 0){
if($time == 0){
header("Location: {$par}");
}else{
header("Refresh: {$time}; url={$par}");
}
}
function session($par){
if ($_SESSION[$par]){
return $_SESSION[$par];
}else{
return false;
}
}
function session_olustur($par){
foreach ($par as $anahtar => $deger){
$_SESSION[$anahtar]=$deger;
}
}
function sef_link($url){
$url = trim($url);
$url = strtolower($url);
$find = array('<b>', '</b>');
$url = str_replace ($find, '', $url);
$url = preg_replace('/<(\/{0,1})img(.*?)(\/{0,1})\>/', 'image', $url);
$find = array(' ', '"', '&', '&', '\r\n', '\n', '/', '\\', '+', '<', '>');
$url = str_replace ($find, '-', $url);
$find = array('é', 'è', 'ë', 'ê', 'É', 'È', 'Ë', 'Ê');
$url = str_replace ($find, 'e', $url);
$find = array('Ã', 'ì', 'î', 'ï', 'I', 'Ã', 'ÃŒ', 'Ã', 'Ã', 'Ä°', 'ı');
$url = str_replace ($find, 'i', $url);
$find = array('ó', 'ö', 'Ö', 'ò', 'ô', 'Ó', 'Ò', 'Ô');
$url = str_replace ($find, 'o', $url);
$find = array('á', 'ä', 'â', 'à ', 'â', 'Ä', 'Â', 'Ã', 'À', 'Â');
$url = str_replace ($find, 'a', $url);
$find = array('ú', 'ü', 'Ü', 'ù', 'û', 'Ú', 'Ù', 'Û');
$url = str_replace ($find, 'u', $url);
$find = array('ç', 'Ç');
$url = str_replace ($find, 'c', $url);
$find = array('Å', 'ÅŸ');
$url = str_replace ($find, 's', $url);
$find = array('Ä', 'ÄŸ');
$url = str_replace ($find, 'g', $url);
$find = array('/[^a-z0-9\-<>]/', '/[\-]+/', '/<[^>]*>/');
$repl = array('', '-', '');
$url = preg_replace ($find, $repl, $url);
$url = str_replace ('--', '-', $url);
return $url;
}
function query($query){
return mysql_query($query);
}
function row($query){
return mysql_fetch_array($query);
}
function rows($query){
return mysql_num_rows($query);
}
{
}
?>
include_once "../blog/connect.php";
include_once "../blog/functie.php";
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Dashboard I Admin Panel</title>
<link rel="stylesheet" href="css/layout.css" type="text/css" media="screen" />
<!--[if lt IE 9]>
<link rel="stylesheet" href="css/ie.css" type="text/css" media="screen" />
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script src="js/jquery-1.5.2.min.js" type="text/javascript"></script>
<script src="js/hideshow.js" type="text/javascript"></script>
<script src="js/jquery.tablesorter.min.js" type="text/javascript"></script>
<script type="text/javascript" src="js/jquery.equalHeight.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$(".tablesorter").tablesorter();
}
);
$(document).ready(function() {
//When page loads...
$(".tab_content").hide(); //Hide all content
$("ul.tabs li:first").addClass("active").show(); //Activate first tab
$(".tab_content:first").show(); //Show first tab content
//On Click Event
$("ul.tabs li").click(function() {
$("ul.tabs li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$(".tab_content").hide(); //Hide all tab content
var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active ID content
return false;
});
});
</script>
<script type="text/javascript">
$(function(){
$('.column').equalHeight();
});
</script>
</head>
<body>
<?php
if(session("login") && session("uye_rutbe") == 1){
require_once "inc/default.php";
}else{
}
if ($_POST){
$kadi= p("kadi");
$sifre = md5(p("sifre"));
if (!$kadi || !$sifre){
echo "kullanıcı adı sifre bos bırakılamaz";
}
else{
$row = $connect->query("SELECT * FROM uyeler WHERE uye_kadi = '$kadi' && uye_sifre = '$sifre'");
$row = $connect->fetch(PDO::FETCH_ASSOC);
if ( $row["uye_id"])
{
$session = array(
"giris_yap" => true,
"uye_id" => $row["uye_id"],
"uye_kadi" => $row["uye_kadi"],
"uye_rutbe" => $row["uye_rutbe"]
);
session_olustur($session);
header("Refresh:0;");
} else {
echo "<font color='red'>Böyle Bir Yönetici Yoktur.</font>";
}
}
}
?>
<div id="giris_yap">
<form action="" method="post">
<table cellpadding="0" cellspacing="0">
<tr>
<td>Gebruikersnaam:</td>
<td><input type="text" name="kadi" /></td>
</tr>
<tr>
<td>Wachtwoord:</td>
<td><input type="password" name="sifre" /></td>
</tr>
<tr>
<td></td>
<td><button type="submit">Inloggen</button></td>
</tr>
</table>
</form>
</div>
</body>
</html>
functie.php
<?php
function p($par, $st =false){
if($st){
return htmlspecialchars(trim($_POST[$par]));
}else{
return trim( $_POST[$par]);
}
}
function g($par){
return strip_tag(trim($_GET[$par]));
}
function kisalt($par,$uzunluk = 50){
if(strlen($par) > $uzunluk){
$par=mb_substr($par,0,$uzunluk,"UTF-8").". .";
}
return $par;
}
function go($par, $time = 0){
if($time == 0){
header("Location: {$par}");
}else{
header("Refresh: {$time}; url={$par}");
}
}
function session($par){
if ($_SESSION[$par]){
return $_SESSION[$par];
}else{
return false;
}
}
function session_olustur($par){
foreach ($par as $anahtar => $deger){
$_SESSION[$anahtar]=$deger;
}
}
function sef_link($url){
$url = trim($url);
$url = strtolower($url);
$find = array('<b>', '</b>');
$url = str_replace ($find, '', $url);
$url = preg_replace('/<(\/{0,1})img(.*?)(\/{0,1})\>/', 'image', $url);
$find = array(' ', '"', '&', '&', '\r\n', '\n', '/', '\\', '+', '<', '>');
$url = str_replace ($find, '-', $url);
$find = array('é', 'è', 'ë', 'ê', 'É', 'È', 'Ë', 'Ê');
$url = str_replace ($find, 'e', $url);
$find = array('Ã', 'ì', 'î', 'ï', 'I', 'Ã', 'ÃŒ', 'Ã', 'Ã', 'Ä°', 'ı');
$url = str_replace ($find, 'i', $url);
$find = array('ó', 'ö', 'Ö', 'ò', 'ô', 'Ó', 'Ò', 'Ô');
$url = str_replace ($find, 'o', $url);
$find = array('á', 'ä', 'â', 'à ', 'â', 'Ä', 'Â', 'Ã', 'À', 'Â');
$url = str_replace ($find, 'a', $url);
$find = array('ú', 'ü', 'Ü', 'ù', 'û', 'Ú', 'Ù', 'Û');
$url = str_replace ($find, 'u', $url);
$find = array('ç', 'Ç');
$url = str_replace ($find, 'c', $url);
$find = array('Å', 'ÅŸ');
$url = str_replace ($find, 's', $url);
$find = array('Ä', 'ÄŸ');
$url = str_replace ($find, 'g', $url);
$find = array('/[^a-z0-9\-<>]/', '/[\-]+/', '/<[^>]*>/');
$repl = array('', '-', '');
$url = preg_replace ($find, $repl, $url);
$url = str_replace ('--', '-', $url);
return $url;
}
function query($query){
return mysql_query($query);
}
function row($query){
return mysql_fetch_array($query);
}
function rows($query){
return mysql_num_rows($query);
}
{
}
?>
Connect.php
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
$host = "localhost";
$database = "blog";
$user = "root";
$password = "";
try {
$connect = new PDO("mysql:localhost={$host};dbname={$database}", $user, $password, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
$connect->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
} catch (PDOException $e) {
return 'Oeps!, Connection Error: '. $e->getMessage();
}
?>
$host = "localhost";
$database = "blog";
$user = "root";
$password = "";
try {
$connect = new PDO("mysql:localhost={$host};dbname={$database}", $user, $password, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
$connect->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
} catch (PDOException $e) {
return 'Oeps!, Connection Error: '. $e->getMessage();
}
?>
- Aar -:
Gelieve in het vervolg bij code de [code][/code]-tags gebruiken.
Hier kan je meer lezen over de mogelijke opmaakcodes.
Alvast bedankt!
Hier kan je meer lezen over de mogelijke opmaakcodes.
Alvast bedankt!
Gewijzigd op 26/04/2015 20:39:48 door - Ariën -
Frank Zane op 26/04/2015 17:20:40:
Undefined Variable: _SESSION
Ik zie nergens session_start().
Engels is beter gangbaarder in de programmeerwereld.
Gewijzigd op 26/04/2015 20:54:15 door Frank Zane