0

I grabbed this piece of code off the Internet and modified it slightly to fit my needs but it doesn't work and I don't know why. I'm sure I've overlooked something but I don't know enough about PHP to know what I'm doing wrong. The uid is showing up, but nothing else. I'm just trying to get information from the MySQL data based on the user's session id. I checked the database to make sure that the uid that shows matches the data -- it does.

<?php

include("connect.php");
session_start();

$uid = $_SESSION['user_id'];

$result = mysql_query("SELECT * FROM users WHERE id = ' . $uid . '");

if ($result) {
   echo "Connect"; } else
   { die('Invalid query: '.mysql_error()); }

$info = mysql_fetch_array($result);

echo "<br>ID: ", $uid;
echo "<br>Full Name: " .$info['full_name'] ;
echo "<br>User Name: " .$info['user_name'] ;
echo "<br>";

?>

p.s. - Yes, I know that mysql_query (and other syntax like it) has been deprecated.

0

2 Answers 2

6
$result = mysql_query("SELECT * FROM users WHERE id = '" . $uid . "'"); // not ' . $uid . '

NOTE: You were searching for . ID . not actual ID

Sign up to request clarification or add additional context in comments.

Comments

2

Query should be as

$result = mysql_query("SELECT * FROM users WHERE id = $uid ");

Assuming id is int in the table

You had

$result = mysql_query("SELECT * FROM users WHERE id = ' . $uid . '");
                                                        ^....   ^.... was the issue. 

1 Comment

Yeah I know but getting little older so cant forget the old school way of writing query i.e. quotes for string date etc and no quotes for integer :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.