pr0cz pr0cz - 20 days ago 4
MySQL Question

check variable in mysql table with php

I want to check a variable in my MySQL table and get some action done if it fits.
I want to check whether the logged in account has the type = d. If so, he should get redirected, if not the normal html code should appear.
But for now, it gets completly ignored.

This is my code

<?PHP
require_once("./include/membersite_config.php");



session_start();

if(!$fgmembersite->CheckLogin())
{
$fgmembersite->RedirectToURL("login.php");
exit;
}
else {
$now = time(); // Checks the time, the homepage gets loaded

if ($now > $_SESSION['expire']) {
session_destroy();
header("Location: http://www.uni-landau.de/vivian/source/expiredLogin/expiredLoginLayout.php");
exit();
}
else {
?>
<?php include "connect.php"?>
<?php include "functions.php"?>
<?php

$check_login = mysql_query("SELECT type FROM users WHERE username='$username'");
$run = mysql_fetch_array($check_login);
$type = $run ['type'];

if ($type == 'd'){

header("Location: http://www.blubb.php"); }
else { //starts html area

?>


The code in the beginning for the time check and the
session_destroy
works fine. After the
else { $check_login = mysql_query
[...] it gets ignored and the page loads even if the account I log in with is
$type == 'd'
.
Can anybody push me in the right direction?

PS: the variables in my mysql table are correct.

Thanks in advance.

EDIT:

The value for
$username
is in my included function.php:

<?php

session_start();

function loggedin() {
if(isset($_SESSION['id_user']) && !empty($_SESSION['id_user'])){

return true;

} else {
return false;

}
}


if(loggedin()){
$user_query = mysql_query("SELECT username, user_level FROM users WHERE id='$my_id'");
$run_user = mysql_fetch_array($user_query);
$username = $run_user['username'];
$user_level = $run_user ['user_level'];
?>


this is my connect.php for the db connection:

<?php

mysql_connect ("host" , "name", "psw");
mysql_select_db("users");

?>

Answer

Solved with two variables checked up :

 $mysqli = new mysqli('host', 'name', 'psw', 'db');
    if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }
    if ($result = $mysqli->query("SELECT `type` FROM users WHERE id_user = 1 ")) {

        $r = mysqli_fetch_array($result);


        }
    if ($result = $mysqli->query("SELECT gruppe FROM users WHERE gruppe = 1 ")) {

        $d = mysqli_fetch_array($result);

        }

            $link = 'link.php';     

        if ($_SESSION['type'] == $r['type'] && $_SESSION['gruppe'] == $d['gruppe']) {     
        printf(' <a href="' .$link. '">
                    <button  style="background-image:url(\'ex.jpg\');">                 
                    </button>
                    </a> ');                

                    }
                    else {
                     printf ('
                    <button  style="background-image:url(\'ex.jpg\');">                 
                    </button>
                    ');

      }                             

    $mysqli->close();

    ?>
Comments