Jump to content

Class, Sql Variable - Resource Id #8


azraelGG

Recommended Posts

im trying to get 1 data column and store it in session variable so i can use it later

i tried to do that on line 47 but without success

when i try print_r($result) i get "resource id #8"

 

here is the class file

<?php
class korisnik{
private $_ime;
private $_prezime;
private $_oib;
private $_adresa;
private $_email;
private $_lozinka;
private $_database;

public function _construct(){

}

//metoda koja provjerava da li je korisnik logiran
public function isLogiran(){
//ukoliko je korisnik logiran
if(isset($_SESSION['logiran'])&& isset($_SESSION['email'])){
return true;
}
//ukoliko korisnik nije logiran idi na index.php i vrati na index.php
else {
if( basename($_SERVER['PHP_SELF']) != "index.php" && basename($_SERVER['PHP_SELF']) != "registracija.php"){
 header('Location: index.php');
}
}
}

//metoda za logiranje
public function getKosrinikLogin($email, $lozinka){
//provjera da li je upisano nešto u polja
$lozinka = sha1($lozinka);
if(!empty($email) && (!empty($lozinka))){
//pravljenje novog korisnika i provjera sql upita
$korisnik = new Database();
$sql = "SELECT * FROM korisnik WHERE email = '$email' AND lozinka = '$lozinka'";
$result = $korisnik->query($sql);

//provjeriti da li je samo jedan rezultat sql upita - provjerava ispravnos podataka
$korisnikCount = mysql_num_rows($result);

if($korisnikCount == 1){
 //podesit session
 $_SESSION['logiran'] = "da";
 $_SESSION['email'] = $_POST['email'];
 print_r($result);
 //ROW 45 HERE --------------------------------------------------- want get field ime from database table
 echo $result[0]['ime'];

}
// ukoliko unos nije ispravan
else {
 echo "Unesite ispravne podatke";
}
}
// ako je polje prazno
else {
echo "Unesite e-mail adresu i šifru";
}
}//end of getKorisnikLogin

//metoda za registraciju
public function registerKorisnik($ime, $prezime, $oib, $adresa, $email, $lozinka){
$lozinka = sha1($lozinka);
//provjera polja
if(!empty($ime) && (!empty($prezime)) && (!empty($oib)) && (!empty($adresa)) && (!empty($email)) && (!empty($lozinka))){
//ako su unešena sva polja provjeri podatke
$sql = "SELECT * FROM korisnik WHERE email = '$email'";
$korisnik = new Database();
$emailCheck = $korisnik->query($sql);
if(mysql_num_rows($emailCheck) == 0){
 //ako email adresa nije zauzeta registriraj korisnika
 $registracija = "INSERT INTO korisnik (ime, prezime, oib, adresa, email, lozinka) VALUES ('{$ime}', '{$prezime}', '{$oib}', '{$adresa}', '{$email}', '{$lozinka}')";

 //ZAŠTO OVAJ RED UPISUJE U BAZU PODATAKA ako ima if
 if($korisnik->zapis($registracija)){
 echo "Uspješno ste se registrirali.";
 }
 else {
 echo "Došlo je do pogreške prilikom registracije. <br>";
 echo mysql_error();
 }
}
else if (mysql_num_rows($emailCheck) != 0){
 echo "Ova e-mail adresa je već zauzeta.";
}
else {
 echo "Došlo je do pogreške, molimo pokušajte ponovo.";
}
}
else {
echo "Unesite sve podatke.";
}
}//end of registerKorisnik
}
?>

 

rest of the code works fine

Link to comment
https://forums.phpfreaks.com/topic/272523-class-sql-variable-resource-id-8/
Share on other sites

MySQL is being thrown out the window, window locked and key melted so I strongly suggest you switch to MySQLi or PDO as per the php website :D.

 

You really need to break your code down and write English comments as many people will discard your post the minute they see a massive chunk of code. The Database::query method appears to return a resource ID so you can call a mysql_fetch_assoc/array() function to retrieve the next row in the result set - of course you're going to change to MySQLi though and use mysqli_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.