I'd like to know how to select a single value from my MySQL table. The table includes columns username
and id
amongst others (id
is auto-increment and username
is unique). Given the username, I want to set a session variable $_SESSION['myid']
equal to the value in the id
column that corresponds to the given username. Here's the code that I've already tried:
session_start();
$name = $_GET["username"];
$sql = "SELECT 'id' FROM Users WHERE username='$name'";
$result = mysql_query($sql);
$value = mysql_fetch_object($result);
$_SESSION['myid'] = $value;
So far I'm getting:
Catchable fatal error: Object of class stdClass could not be converted to string.
Casting $value
to type string does not fix the problem.