2

I'm a little new to PHP and MYSQL. I'm creating an admin panel, in the MySQL database I have a column called admin.

I want it to check the column, So if admin has 0 on it, it will header to index.php but if it has 1 it will header to admin.php.

I would also like some help, For admin.php I want something like, if you were not on the database (checks if admin has 1 in the username), it will head somewhere else.

Admin.php code:

<?php
session_start();
include_once 'dbconnect.php';

if (isset($_SESSION['user']) != "") {
    header("Location: home.php");
}

if (isset($_POST['btn-login'])) {
    $uname = mysql_real_escape_string($_POST['uname']);
    $admin = mysql_real_escape_string($_POST['admin']);
    $upass = mysql_real_escape_string($_POST['pass']);
    $res = mysql_query("SELECT * FROM users WHERE admin = '1'");
    $row = mysql_fetch_array($res);

    if ($row['admin'] == 1) {
        header("Location: admin.php");
    }
    else {
        echo 'Shithead';
    }
}
?>
1
  • If you are using SQL query like SELECT * FROM users WHERE admin='1' it will always give you the record with admin 1. What's your problem please elaborate it more. Commented Sep 19, 2015 at 8:41

1 Answer 1

1

For a start you need to fetch the right row for the user. You are fetching only rows that are admins !!! Something like this.

$res=mysql_query("SELECT * FROM users WHERE uname='$uname' and pass='$pass'");

assuming that your db fields are called uname and pass.

You need to get this working and then ask a new question for the rest.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.