Jump to content

Notice: Undefined index: login and Call to undefined method PDO::fetch() error


Ersan

Recommended Posts


I looked at a tutorial on youtube to make a blog.

I need to be connected after logging in my admin login with the admin panel.

What is my mistake here?

Thank you very much!



index.php

<?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>


function.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

<?php

session_start();

$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 'Hay Allah!, Connection Error: '. $e->getMessage();
}

?>

 

It is actually NOT at the top of the page - it is your topic title. Could you give us the ENTIRE message so that we can locate the lines involved since I don't see the use of the vord 'index' anywhere. Maybe you could give us a snippet of the particular lines?

 

What it means is that you are using login as an index to an array and that particular index does not (yet) exist. Also the second error msg means that you have not defined the object yet (or it failed) and therefore you cannot use any of that object's methods yet.

@Ginerjm,

 

I get the errors:

Notice: Undefined index: login in C:\Users\Ersan\XAMPP\htdocs\blog\functie.php on line 35

 

Fatal error: Call to undefined method PDO::fetch() in C:\Users\Ersan\XAMPP\htdocs\admin\index.php on line 74

 

You can see the line numbers on these websites:

index.php: http://pastie.org/10115184#8

functie.php: http://pastie.org/10115193

connect.php: http://pastie.org/10115194

 

Thank you very much!

 

Notice: Undefined index: login in C:\Users\Ersan\XAMPP\htdocs\blog\functie.php on line 35

Use isset when checking to see if a session variable exists

      if (isset($_SESSION[$par])){

 

Fatal error: Call to undefined method PDO::fetch() in C:\Users\Ersan\XAMPP\htdocs\admin\index.php on line 74

The fetch() method is part of PDOStatement object ($row) not the PDO object ($connect).

$result = $connect->query("SELECT * FROM uyeler WHERE uye_kadi = '$kadi' && uye_sifre = '$sifre'");
$row = $result->fetch(PDO::FETCH_ASSOC);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.