thedigicraft / Atom.CMS

Atom.CMS
56 stars 52 forks source link

Developing a Dynamic Website 2014 - Part 28 #95

Closed maaka closed 9 years ago

maaka commented 9 years ago

I know there are about 3 posts just like mine, but nothing recent. I've gone as far as to copy login.php from repo, and I'm still unable to get directed to index.php after typing in credentials in login field. I tried a few things to ensure at least my side was correct. I added error checking after header location per another post, and no errors. To ensure my connection.php config was correct, I changed password in the connections file and instantly got an error. Changed it back, and all was well. Like I said this is direct from repo, but posted below is my login.php script.
<?php

Start Session:

session_start();

Database Connection:

include('../config/connection.php');

if($_POST) {

$q = "SELECT * FROM users WHERE email = '$_POST[email]' AND password = SHA1('$_POST[password]')";
$r = mysqli_query($dbc, $q);

if(mysqli_num_rows($r) == 1) {

    $_SESSION['username'] = $_POST['email'];
    header('Location: index.php');

}else {

      echo mysqli_error($dbc).'<br>'.$q; // show any mysql errors and echo out the query to look for other errors     

  }

}

?>

<!DOCTYPE html>

``` Admin Login ``` ```
Login
```
maaka commented 9 years ago

Figured it out, it was a noob mistake. In index.php i didn't capitalize "$_SESSION". Hopefully this helps someone else

creptor commented 9 years ago

it's good that you have figuered it out. please now close the issue