vendredi 27 janvier 2017

Two tables values matching equals a value

Thanks for having a look at this, really baffled me and I don't know what to do.

Basically I am wanting to display some data if the user name matches the user name on the data's table. You'll understand when you see the code.

So here is the code I am using to try display it on my main page:

<?php
if($login_user == $feedbackuser)
{
echo'
<p>Hey</p>
';                       
}
?>

Then here is my code connecting to the SQL data base and trying to call information from each table.

Connecting to table 1:

<?php
include('connection.php');
session_start();
$user=$_SESSION['user'];
$ses_sql = mysqli_query($db,"SELECT user FROM feedback WHERE user='$user'");
$row=mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);
$feedbackuser=$row['user'];
?>

Connecting to Table 2:

<?php
include('connection.php');
session_start();
$user_check=$_SESSION['username'];

$ses_sql = mysqli_query($db,"SELECT username FROM users WHERE username='$user_check' ");



$row=mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);

$login_user=$row['username'];
$admin=$row['admin'];

if(!isset($user_check))
{
header("Location: index.php");
}
?>

So basically I want a sentence to be displayed if their username from table 1 matches user from table 2.

If you could help me further that would be great. If you take a look at the screenshot before I explain more... http://ift.tt/2kv3ji3

So if the username from table 1 matches user from table 2 then "writing" from table 2 will be displayed on the page.

Thanks in advance for the help! James

Aucun commentaire:

Enregistrer un commentaire