Skip to content
Advertisement

SQL: mysqli_query, no output

session_start();
$user=$_SESSION['username'];
$con=mysqli_connect("$host","$username","$password","$db_name");
$sql1="SELECT UserID FROM User WHERE username='$user'";
$query=mysqli_query($con,$sql1);
echo $query;

Im not sure what’s the problem with this, I’ve tried searching around here and tried different ways of writing the syntax and checking for errors in parameter but still no output for the command. What am i missing here?

UPDATE

$sql1="SELECT UserID FROM User WHERE username='$user'";
$query=mysqli_query($sql1,$con);
$row=mysqli_fetch_array($query);
$uid=$row[0];
echo $uid;

As answered by the others, I tried doing this. There is still no output or an output of 0 was given. Where if I tried the query in sql, it shows the right one.

UPDATE 2

It tried the var_dump() command and it returns NULL. Does that mean it can’t read the database?

Advertisement

Answer

I was able to do some workaround with my problem using mysql syntax. Still not able to determine the problem with mysqli but able to finished my task. Thanks for answering guys.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement