Jump to content

cardwell164

Members
  • Posts

    12
  • Joined

  • Last visited

cardwell164's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hello! First of all, i would like to thank everyone in this community as this is where i post most of the problems that i can no longer fix on my own. and everytime i do, i get all the help i need and with a 100% success rate. Anyway, i am following a tutorial, however the tutorial is based on a MAC environment and i am working on windows. I think this is a problem with the DIRECTORY_SEPARATOR but i might be wrong. I am getting this error message "Notice: Use of undefined constant LIB_PATH - assumed 'LIB_PATH' in C:\wamp\www\beyond_basics_photogallery\includes\database.php on line 2" i will just post the code that is relevant to this error. here is the code for database.php: (config.php is in the same folder with database.php) require_once(LIB_PATH.DS."config.php"); and this is my initialize.php where i initialized my DIRECTORY_SEPARATOR. this is also located in the same folder with database.php <?php // Define the core paths // Define them as absolute paths to make sure that require_once works as expected defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR); defined('SITE_ROOT') ? null : define('SITE_ROOT', DS.'wamp'.DS.'www'.DS.'beyond_basics_photogallery'); defined('LIB_PATH') ? null : define('LIB_PATH', SITE_ROOT.DS.'includes'); // load config file first require_once(LIB_PATH.DS.'config.php'); // load basic functions next so that everything after can use them require_once(LIB_PATH.DS.'functions.php'); // load core objects require_once(LIB_PATH.DS.'session.php'); require_once(LIB_PATH.DS.'database.php'); // load database-related classes require_once(LIB_PATH.DS.'user.php'); ?> and this is the path to my project folder: C:\wamp\www\beyond_basics_photogallery I have tried everything i could but i am completely lost as to what is causing this. could it be the SITE_ROOT statement? i appreciate any help. thanks!
  2. I am following this oop registration and login tutorial using PDO. It seems easy to understand that's why i am following it but i am currently having an issue when logging in. I don't have issues when registering as it pushes the data into the database but when i try to login its giving me this error "SQLSTATE[42000]: Syntax error or access violation: 1630 FUNCTION lar.COUNT does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual". "lar" is the name of my database. i double checked the spelling in my code to check if its a typo error but there is nothing wrong that i can find. i am not sure if the problem is with the syntax of my sql query or if theres a problem with the function i created to check for the query. here is the code for my login.php (i did not include the html code in here to save space) <?php require 'core/init.php'; $general->logged_in_protect(); if(empty($_POST) === false) { $username = trim($_POST['username']); $password = trim($_POST['password']); if(empty($username) === true || empty($password) === true) { $errors[] = 'Sorry, but we need your username and password.'; } else if($users->user_exists($username) === false) { $errors[] = 'Sorry that username does not exist'; } else if($users->email_confirmed($username) === false) { $errors[] = 'Sorry, but you need to activate your account. Please check your email.'; } else { $login = $users->login($username, $password); if($login === false) { $errors[] = 'Sorry, that username/password is invalid'; } else { session_regenerate_id(true); //destroying the old session and creating a new one $_SESSION['id'] = $login; header('Location: home.php'); exit(); } } } ?> and this is my code to my users class where i suspect there is a problem. users.php (i only included the user_exists and login function since all the rest seems to work fine) class Users { private $_db; public function __construct($database) { $this->_db = $database; } public function user_exists($username) { $query = $this->_db->prepare("SELECT COUNT(`id`) FROM `users` WHERE `username` = ?"); $query->bindValue(1, $username); try { $query->execute(); $rows = $query->fetchColumn(); if($rows == 1) { return true; } else { return false; } } catch(PDOException $e) { die($e->getMessage()); } } public function login($username, $password) { global $bcrypt; $query = $this->_db->prepare("SELECT `password`, `id`, FROM `users` WHERE `username` = ?"); $query->bindValue(1, $username); try { $query->execute(); $data = $query->fetch(); $stored_password = $data['password']; $id = $data['id']; #hasing the supplied password and comparing it with the stored hashed password. if($bcrypt->verify($password, $stored_password) === true) //using the verify method to compare the password with hashed passwords { return $id; } else { return false; } } catch(PDOException $e) { die($e->getMessage()); } } i have been at this for almost half a day now and still couldnt figure this out. i think im missing something that might be very simple for you guys here but i just dont know what it is. i am hoping that comeone could help me with this. i would greatly appreciate it. thanks!
  3. thank you so much sir. you have been very helpful.
  4. i just started learning pdo and read this tutorial. read everything that was on it and somehow im having this problem and im stuck. anyway here is the code that i wrote. <?php $id = 5; try { $conn = new PDO('mysql:host=localhost;dbname=pdotuts', 'root', ''); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $conn->prepare('SELECT * FROM table WHERE id = :id'); $stmt->execute(array ( 'id' => $id )); while($row = $stmt->fetch()) { print_r($row); } } catch(PDOException $e) { echo 'ERROR: '. $e->getMessage(); } ?> i saved the file as index.php and ran it in my browser. for some reason its giving me this error "ERROR: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table WHERE id = '5'' at line 1". i have been trying to debug this thing but had no luck in correcting it. i am hoping that someone could help me with this. i would really appreciate it.
  5. thanks for the advice sir. i will take note of that.
  6. it was a stupid mistake sir. in my connect.php, i called the wrong database name. instead of registerlogin, i had it loginregister. it turned out i was barking at the wrong tree. i wasnt able to include the die function because the tutorial didnt include it. anyhow, your help was the best!
  7. you dont know how thankful i am to you sir. i just solved my problem. i do agree with you that phpacademy's coding style is coded somewhat poorly. however its the best resource i got that gets things explained very well. i have to hand it to alex though, he explains things very well and always says in the end why this particular function/technique etc. is useful. are there any tutorials that you can recommend?
  8. by the way i tried to echo the query and it displayed it correctly
  9. thanks again for the help sir. that part is fixed now. however i have encountered another problem its now saying: Warning: mysql_result() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\registerlogin\core\functions\users.php on line 34 i really dont know why its saying that. i have double checked that function and i dont see anything wrong there. i hope you will still help me. anyway here is my code function user_exists($username) { $username = sanitize($username); $query = mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username'"); return (mysql_result($query, 0) == 1) ? true : false; } could it be something wrong with my apache version?
  10. thanks for that sir you have been very helpful. i was able to identify the problem now. its not returning any results. i am debugging it as i am posting this
  11. im still new to php and i mostly get my learnings off the internet. i copy the codes to check if they run correctly and understand them afterwards. thanks for the help guys. however im still experiencing the same problem
  12. hi guys. im a newbie in this forum and im glad that i found this. anyway, i have a problem with my code. i am creating a register and login application using php. however its not passing the data properly. i have tried to echo it and still its not showing. can anybody help me on this please? any assistance would be greatly appreciated here is my code for my init.php <?php session_start(); require 'database/connect.php'; require 'functions/general.php'; require 'functions/users.php'; if (logged_in() == true) { $session_user_id = $_SESSION['userid']; $user_data = user_data($session_user_id, 'userid', 'username', 'password', 'firstname', 'lastname', 'email'); } $errors = array(); ?> and this is my users.php which i think where lies the problem. i will just include the code of the function that creates the error. <?php function user_data($userid) { $data = array(); $userid = (int)$userid; $func_num_args = func_num_args(); $func_get_args = func_get_args(); if($func_num_args > 0) { unset($func_get_args[0]); $fields = '`' . implode('', $func_get_args) . '`'; $data = mysql_fetch_assoc(mysql_query("SELECT '$fields' FROM users WHERE userid = '$userid'")); print_r($data); return $data; } } ?> supposedly it should print the query stored in $data however its not doing that
×
×
  • 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.