azraelGG Posted December 30, 2012 Share Posted December 30, 2012 (edited) 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 Edited December 30, 2012 by azraelGG Quote Link to comment https://forums.phpfreaks.com/topic/272523-class-sql-variable-resource-id-8/ Share on other sites More sharing options...
Barand Posted December 30, 2012 Share Posted December 30, 2012 That's because result is a resource - you need to use the result to fetch the returned row $row = $result->fetch_row(); echo $row[0]; Quote Link to comment https://forums.phpfreaks.com/topic/272523-class-sql-variable-resource-id-8/#findComment-1402214 Share on other sites More sharing options...
azraelGG Posted December 30, 2012 Author Share Posted December 30, 2012 i think that fetch_row() is for PDO only but my connecting is not over PDO in this case so i used standard $row = mysql_fetch_assoc($result) thanks for tip Quote Link to comment https://forums.phpfreaks.com/topic/272523-class-sql-variable-resource-id-8/#findComment-1402215 Share on other sites More sharing options...
Barand Posted December 30, 2012 Share Posted December 30, 2012 When I saw $korisnik->query($sql); I thought you were using mysqli Quote Link to comment https://forums.phpfreaks.com/topic/272523-class-sql-variable-resource-id-8/#findComment-1402218 Share on other sites More sharing options...
cpd Posted December 30, 2012 Share Posted December 30, 2012 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 . 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() Quote Link to comment https://forums.phpfreaks.com/topic/272523-class-sql-variable-resource-id-8/#findComment-1402251 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.