Peršokti į turinį
  • ŽAIDIMAI
  • , ŽAIDIMAI
  • ŽAIDIMAI

Pagalba dėl PDO: (traukimas iš mysql)


Ši tema yra neaktyvi. Paskutinis pranešimas šioje temoje buvo prieš 3429 dienas (-ų). Patariame sukurti naują temą, o ne rašyti naują pranešimą.

Už neaktyvių temų prikėlimą galite sulaukti įspėjimo ir pranešimo pašalinimo!

Recommended Posts

Pasikeičiau į mysqli kodą, bet gaunu 1 klaidą iš traukimo: Undefined variable: fixai

Kodas: 
<? echo $row['fixai']; ?>

 

<?php
						if (version_compare(PHP_VERSION, '5.3.7', '<')) {
							exit("Sorry, Simple PHP Login does not run on a PHP version smaller than 5.3.7 !");
						} else if (version_compare(PHP_VERSION, '5.5.0', '<')) {
							require_once("inc/libraries/password_compatibility_library.php");
						}
						require_once("inc/config/db.php");
						require_once("inc/classes/Login.php");
						$login = new Login();
						if ($login->isUserLoggedIn() == true) {
							echo "
							<div class=\"head\">
								<div class=\"center\">
									<span class=\"hello\">Sveikas atvykes, <span class=\"name\">"; echo $_SESSION['user_name']; echo"</span>! </span>
									<div class=\"user\">
										<div class=\"avatar\">
											<img src=\"./images/avatar.png\" />
										</div>
										<div class=\"userset\">
											<span class=\"t\">
												<a href=\"#\">Profilis</a> | <a href=\"index.php?logout\">Atsijungti</a> | <a href=\"#\">Administratorius</a> | <a href=\"#\">keitykla</a>
											</span><br />
											<span class=\"b\">
												Žinutės (<a href=\"#\">24</a>) | Fixai (<a href=\"#\">"; echo $fixai;  echo "</a>) | Taškai (<a href=\"#\">256</a>)
											</span>
										</div>
										<div class=\"ct\">
											Klausaisi: 00:26 Užsidirbai Fixų: 0,20 | <a href=\"#\">Atsiimti</a>
										</div>
									</div>		
								</div>
							</div>";
						} else {
							echo "
							<div class=\"head\">
								<div class=\"center\">
									<div class=\"quest\">
										Sveikas atvykęs, klausytojau! 
										<form method=\"post\" action=\"index.php\" name=\"loginform\">
											<input id=\"login_input_username\" class=\"login_input\" type=\"text\" name=\"user_name\" placeholder=\"slapyvardis\" required />
											<input id=\"login_input_password\" class=\"login_input\" type=\"password\" name=\"user_password\" placeholder=\"*******\" autocomplete=\"off\" required />
											<input type=\"submit\"  name=\"login\" value=\"Prisijungti\" />
										</form> 
											| <a href=\"register.php\">Registruotis</a> | Pamiršai slaptažodį? <a href=\"#\">Spausk čia</a>
									</div>
								</div>
							</div> ";
						} 
					?>

tame inc/classes/Login.php yra tas $fixai

 

Login

<?php

/**
 * Class login
 * handles the user's login and logout process
 */
class Login
{
    /**
     * @var object The database connection
     */
    private $db_connection = null;
    /**
     * @var array Collection of error messages
     */
    public $errors = array();
    /**
     * @var array Collection of success / neutral messages
     */
    public $messages = array();

    /**
     * the function "__construct()" automatically starts whenever an object of this class is created,
     * you know, when you do "$login = new Login();"
     */
    public function __construct()
    {
        // create/read session, absolutely necessary
        session_start();

        // check the possible login actions:
        // if user tried to log out (happen when user clicks logout button)
        if (isset($_GET["logout"])) {
            $this->doLogout();
        }
        // login via post data (if user just submitted a login form)
        elseif (isset($_POST["login"])) {
            $this->dologinWithPostData();
        }
    }

    /**
     * log in with post data
     */
    private function dologinWithPostData()
    {
        // check login form contents
        if (empty($_POST['user_name'])) {
            $this->errors[] = "Username field was empty.";
        } elseif (empty($_POST['user_password'])) {
            $this->errors[] = "Password field was empty.";
        } elseif (!empty($_POST['user_name']) && !empty($_POST['user_password'])) {

            // create a database connection, using the constants from config/db.php (which we loaded in index.php)
            $this->db_connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);

            // change character set to utf8 and check it
            if (!$this->db_connection->set_charset("utf8")) {
                $this->errors[] = $this->db_connection->error;
            }

            // if no connection errors (= working database connection)
            if (!$this->db_connection->connect_errno) {

                // escape the POST stuff
                $user_name = $this->db_connection->real_escape_string($_POST['user_name']);

                // database query, getting all the info of the selected user (allows login via email address in the
                // username field)
                $sql = "SELECT user_name, user_email, user_password_hash, fixai, taskai
                        FROM users
                        WHERE user_name = '" . $user_name . "' OR user_email = '" . $user_name . "';";
                $result_of_login_check = $this->db_connection->query($sql);

                // if this user exists
                if ($result_of_login_check->num_rows == 1) {

                    // get result row (as an object)
                    $result_row = $result_of_login_check->fetch_object();

                    // using PHP 5.5's password_verify() function to check if the provided password fits
                    // the hash of that user's password
                    if (password_verify($_POST['user_password'], $result_row->user_password_hash)) {

                        // write user data into PHP SESSION (a file on your server)
                        $_SESSION['user_name'] = $result_row->user_name;
                        $_SESSION['user_email'] = $result_row->user_email;
                        $_SESSION['user_login_status'] = 1;
						
						$row = mysql_fetch_row($sql);
						$fixai = $row[3];
						

                    } else {
                        $this->errors[] = "Wrong password. Try again.";
                    }
                } else {
                    $this->errors[] = "This user does not exist.";
                }
            } else {
                $this->errors[] = "Database connection problem.";
            }
        }
    }

    /**
     * perform the logout
     */
    public function doLogout()
    {
        // delete the session of the user
        $_SESSION = array();
        session_destroy();
        // return a little feeedback message
        $this->messages[] = "You have been logged out.";

    }

    /**
     * simply return the current state of the user's login
     * @return boolean user's login status
     */
    public function isUserLoggedIn()
    {
        if (isset($_SESSION['user_login_status']) AND $_SESSION['user_login_status'] == 1) {
            return true;
        }
        // default return
        return false;
    }
}


padetu kas?

Nuoroda į komentarą
Dalintis per kitą puslapį

Ši tema yra neaktyvi. Paskutinis pranešimas šioje temoje buvo prieš 3429 dienas (-ų). Patariame sukurti naują temą, o ne rašyti naują pranešimą.

Už neaktyvių temų prikėlimą galite sulaukti įspėjimo ir pranešimo pašalinimo!

Svečias
Ši tema yra užrakinta.
  • Šiame puslapyje naršo:   0 nariai

    • Nėra registruotų narių peržiūrinčių šį forumą.

Skelbimai


×
×
  • Sukurti naują...