Jump to content

PHP scripts not functioning correctly


wizzy886
Go to solution Solved by Ch0cu3r,

Recommended Posts

So i have the problem where the registration was working before, but now isn't and now it isn't. On top of this the actual login doesn't work either. I honestly don't know what is wrong with it so can i please have some guidance. I have troubleshot all of that I know how to and tried to output any error messages but fail in doing so. Thanks.

index.php

login.php

register.php

connection.php

footer.php

header.php

Link to comment
Share on other sites

you need to tell us what you found when you were troubleshooting the problem. in what file and at what line/statement did you find that the code was not doing what you expected and what exact symptom are you getting and at what point during the process that leads you to believe the process isn't doing what you expect?

Edited by mac_gyver
Link to comment
Share on other sites

Sorry, It basically looks like its submitting something (in both registration and login). After this nothing. Ive tried to output the results of the script throughout its process with little luck. The main problems are in registration and login if you could give them a look over please. Im sure its something ive just missed. 

Edited by wizzy886
Link to comment
Share on other sites

the only things that are apparent in your code is there isn't a session_start() statement, so the login won't actually remember the logged in state, but registration should work, and the use of or trigger_error() as error handling logic doesn't address the execution path your code takes, and is dependent on php's error_reporting/display_errors settings, so your code could have database errors, but you might never know it.

 

what does adding the following two lines, immediately after the first opening <?php tag in your register.php page, show -

ini_set("display_errors", "1");
error_reporting(-1);
Edited by mac_gyver
Link to comment
Share on other sites

  • Solution

On line 20 in register.php you should be assigning the username to $username not $password

$password = mysqli_real_escape_string($dbc, $trimmed['username']);

In login.php you are not using sessions properly

echo "success";
session_start();
$_SESSION['username'] = mysqli_fetch_array($r, MYSQLI_ASSOC);

sesssion_start() should be called before you ouput anything to the browser. I recommend putting it on line 1 of header.php

 

To set the username data to the session you need to do

$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
$_SESSION['username'] = $row['username'];
$_SESSION['user_id'] = $row['user_id'];
$_SESSION['user_level'] = $row['user_level'];
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.