How can i retrieve selected value of the 'level' column from the table VBmembers to set it as $level
variable?
session_start();
if (isset($_SESSION['user']))
{
$user = $_SESSION['user'];
$query = "SELECT level FROM VBmembers WHERE user='$user'";
$level = queryMysql($query);
$loggedin = TRUE;
}
else $loggedin = FALSE;
queryMysql function code
function queryMysql($query)
{
$result = mysql_query($query) or die ('ivalid query: ' . mysql_error());
return $result;
}
You need a couple of more steps, most importantly fetching the data in a usable way from the result:
$user = $_SESSION['user'];
$query = "SELECT level FROM VBmembers WHERE user='$user'";
$result = queryMysql($query);
$row = mysql_fetch_array($result);
$level = $row['level'];
$loggedin = TRUE;
As I stated in comments, your script is at risk for SQL Injection Attacks.
If you can, you should stop using mysql_*
functions . These extensions have been removed in PHP 7. Learn about prepared statements for PDO and MySQLi and consider using PDO, it's really not hard .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.