PeterLazarov Posted May 3, 2014 Share Posted May 3, 2014 (edited) Hello!I am new to PHP programming and am currently working on an account system. I have posted my work so far. From what I understand the problem is that when I log in the php script doesn`t acknowledge it and acts as if noone is logged in. Thanks in advace! Here are my files: users.sql : CREATE TABLE IF NOT EXISTS `users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(30) DEFAULT NULL, `password` varchar(255) DEFAULT NULL, `fullname` varchar(100) DEFAULT NULL, `location` varchar(200) DEFAULT NULL, `gender` varchar(10) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; auth_check.php common.php dashboard.php index.php login.php logout.php register.php auth_check.php Edited May 3, 2014 by PeterLazarov Quote Link to comment https://forums.phpfreaks.com/topic/288217-account-system/ Share on other sites More sharing options...
mac_gyver Posted May 3, 2014 Share Posted May 3, 2014 what debugging have you done to pin down where the problem is at? do you have php's error_reporting set to E_ALL and display_errors set to ON so that php will help you by reporting and displaying the errors it detects? Quote Link to comment https://forums.phpfreaks.com/topic/288217-account-system/#findComment-1478077 Share on other sites More sharing options...
PeterLazarov Posted May 3, 2014 Author Share Posted May 3, 2014 what debugging have you done to pin down where the problem is at? do you have php's error_reporting set to E_ALL and display_errors set to ON so that php will help you by reporting and displaying the errors it detects? I just added ini_set("display_errors", 1); ini_set("track_errors", 1); ini_set("html_errors", 1); error_reporting(E_ALL); and no error was found Quote Link to comment https://forums.phpfreaks.com/topic/288217-account-system/#findComment-1478082 Share on other sites More sharing options...
TrickyInt Posted May 3, 2014 Share Posted May 3, 2014 You haven't Session_start() on your login.php page, neither on your auth_check.php page - so it cannot access anything from it. Maybe you should just add session_start() in your common.php file, if it's included at the top of every other page/file? Good luck Quote Link to comment https://forums.phpfreaks.com/topic/288217-account-system/#findComment-1478092 Share on other sites More sharing options...
PeterLazarov Posted May 3, 2014 Author Share Posted May 3, 2014 (edited) When i was going trough the registraion I found two new mistakes in register.php that i didn`t see the last time.They are : $register = $_GET['register']; ( Undefined index) and $success = mysql_query("INSERT INTO users(username, password, fullname, location, gender) VALUES ('$username', '$password', '$full_name','$location','$gender')"); ( Undefined variable)EDIT: I found a way that makes the error statement go away, but it seems a little questionable. The solution(??) is: Undefined index.Couldn't you just declare it in the line before to get rid of the error.$_GET['register']=''; Edited May 3, 2014 by PeterLazarov Quote Link to comment https://forums.phpfreaks.com/topic/288217-account-system/#findComment-1478105 Share on other sites More sharing options...
mac_gyver Posted May 3, 2014 Share Posted May 3, 2014 the way to fix errors is to find out what is causing them and fix the problem. setting $_GET['register']=''; will make the error message go away, but it will also prevent your registration script from working. for your undefined index in $_GET['register'], the correct way of handling a variable that is optional is to use isset() - $register = isset($_GET['register']) ? (int)$_GET['register'] : false; as to your login not working, what exactly happens? what page, result, or output message do you get? Quote Link to comment https://forums.phpfreaks.com/topic/288217-account-system/#findComment-1478119 Share on other sites More sharing options...
Jacques1 Posted May 4, 2014 Share Posted May 4, 2014 Hi, I think you shouldn't use this code at all. Whoever wrote the “tutorial” knows less about PHP than you do. It's clearly the work of an amateur who has just started with PHP himself. You definitely cannot use this on an actual website. And you cannot use it for learning either, because the code is heavily outdated and simply bad. I understand that it's tempting to just copy and paste some PHP code from a random website and adjust it to your needs. But you have to realize that a lot of those “tutorial writers” have absolutely no idea what they're doing. Most of the time, the tutorial itself is just the copy of the copy of the copy of some crap code from the 90s. Trying to learn PHP from this is like trying to learn nuclear physics from Paris Hilton. You should write your own code. Yes, this takes some time and may seem less convenient. But you'll actually learn the language and become better. When you steal code from tutorials, all you do is perpetuate low quality. Learn PHP. For a login system, you'll need to know the following: how to access a MySQL database from PHP the basics of web security (prepared statements, HTML-escaping etc.) how to securely hash passwords And of course the basics of HTML and possibly JavaScript. The Mozilla Developer Network will be helpful with that. Keep away from “w3schools”. I you have any questions, I'm sure people will gladly help you. Quote Link to comment https://forums.phpfreaks.com/topic/288217-account-system/#findComment-1478125 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.