Retrieve only that user datas

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
saran.tvmalai
Forum Newbie
Posts: 4
Joined: Sat Aug 28, 2010 4:07 am

Retrieve only that user datas

Post by saran.tvmalai »

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

Code: Select all

<?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>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Retrieve only that user datas

Post by requinix »

It shows everything because you didn't try to tell it otherwise. Give it a shot first, and if you can't get it then come back.

Also, use the "PHP Code" button to highlight code. Not

Code: Select all

 tags.
Post Reply