I have a small problem using the Where clause for PHP/MySQL in the code shown below:
<?php
$con=mysqli_connect("host","username","password","database");
//Note that I have replaced my parametres just for this question
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//Request Session ID
$id = $_SESSION['uid'];
echo "Session ID = ' . $id;
echo "<br>";
//Request Username
echo "Username = " . mysqli_query($con,"SELECT username FROM 'users' WHERE id = 4");
?>
The output of this is (after logging in on my separate login page):
Session ID = 4
Username =
So it is evident that there is an issue with the where clause. There is no issue with the connection parametres as far as I am aware. When I run the MySQL command in PHPmyadmin I get the expected result of 'Admin'. My inputs are correctly named.
I have no idea what is causing this and I can't find any similar problems on the forum. Any help would be appreciated. Thanks.
UPDATE
I have adapted the below answers to make this code:
<?php
// Only run this script if the sendRequest is from my flash application
if ($_POST['sendRequest'] == "parse") {
//conection:
$con=mysqli_connect("mysqlXX.000webhost.com","a4935911_***","***","a4935911_***");
$id = $_SESSION['uid'];
$getuname = mysqli_fetch_assoc(mysqli_query($con, "SELECT username FROM users WHERE id = $id"));
$uname = $getuname ['username'];
// Print 1 var to flash
print "var1=The username of this user is $uname.";
}
?>
Which is triggered by my flash application. This works fine if I do not use session ID variable and just use e.g. 4 as my id value but I need to use the session ID for this. Any ideas what is up with this?