Jump to content

Recommended Posts

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 by PeterLazarov
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 ;)

Link to comment
Share on other sites

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 by PeterLazarov
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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:

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.