If mysql data = php variable issue

Currently I’m trying to make it so if someone logs in his the same id as the php $ variable then it will redirect them. although I am not sure why it isn’t working.

$query = “SELECT * FROM login WHERE username= '”.$_SESSION[‘username’]."’";
$result = $connection->query($query);
if($result->num_rows > 0){
$userData = $result->fetch_assoc();
if($userData[‘id’] = $siteokid){
header(“Location: admin.php”);
header("Location: index.php ");
echo “”;

And what should that mean?

It is allowing all users no matter the id number to be put into admin.php.

then you must check that ID on the admin.php

There’s an = sign missing here. It should be:

if ($userData['id'] == $siteokid) {

= is for assignment, so you’re changing the value of $siteokid rather than matching against it.

Sponsor our Newsletter | Privacy Policy | Terms of Service