Jump to content

Retrieve only that user datas


saran.tvmalai

Recommended Posts

Dear All,

 

I have login script already. i have two database one is users and another one is reference  in both user_name is common. In this if a user login and search the refid means that user datas onle possible to retrieve. for others datas they cant access. i wrote the below code but it display all user datas. kindly help me

 

 

<?php
session_start();

if (!$_SESSION["user_name"])
        {
        // User not logged in, redirect to login page
        Header("Location: login.php");
  /     }

// Member only content
// ...
$con = mysql_connect('localhost','root','');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("login", $con);


$user_name = $_POST['user_name'];


$query = "select * from reference,users where  reference.user_name=users.user_name and reference.refid='$refid'";
$result = mysql_query($query) or trigger_error('MySQL encountered a problem<br />Error: '  . mysql_error() . '<br />Query: ' . $query);


while($row = mysql_fetch_array($result))
  {
  echo $row['refid'];
  echo $row['origin'];
  echo $row['dest'];
  echo $row['date'];
  echo $row['exdate'];
  echo $row['user_name'];
  }


echo "<p><a href=\"logout.php\">Click here to logout!</a></p>";
?>

 

<html>

<form method="post" action="final.php">

Ref Id:<input type="text" name="refid">

<input type="submit" value="submit" name="submit">

</html>

 

 

Link to comment
https://forums.phpfreaks.com/topic/212822-retrieve-only-that-user-datas/
Share on other sites

You call for a variable named $refid in your query, yet this variable doesn't exist before the query is executed, thus the variable's value will be empty, making your query look like this:

 

SELECT * FROM reference.users WHERE reference.user_name = users.user_name AND reference.refid = ''

 

I would also recommend that you capitilize the keywords in your query, like SELECT, FROM, WHERE, and AND.  If makes t easier to read.

 

Anyway, so right now you're selecting everything from the reference.users table where reference.user_name is equal to users.user_name and where the reference.refid is empty.  Unless I'm missing something.  I think the problem is here:

 

WHERE reference.user_name = users.user_name

 

You're telling it to select everything from the reference users table where the names are the same, which you said they were.  You collect the POST variable user_name, why not use that in your query?

 

$user_name = $_POST['user_name'];
$refid = $_POST['refid'];

$query = "SELECT * FROM reference.users WHERE reference.user_name = '".$user_name."' AND reference.refid = '".$refid."'";

 

Without more background into what exactly you're doing (I'm having difficulties understanding your description,) I can't help much more.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.