php - Display content if row == 1 if row ==0 do not display -
so have log in script creates $_session based on username of user logging in. on page wish display content if row user has 1 in it. if has 0 in row, not display content. having issues here no matter i've tried, not display yes no matter user log in with.
test1 = 1
test2 = 0
<? require_once 'dbinfo.php'; $sess = $_session['authuser']; $link = mysqli_connect($servername, $username, $password); if (!$link) { die('could not connect: ' . mysqli_error($link)); } mysqli_select_db($link, $database) or trigger_error(mysqli_error($link)); $acc = "select username admins username = '$sess'"; $result = mysqli_query($link, $acc) or trigger_error(mysqli_error($link)); ob_start(); while($row = $result->fetch_assoc()) { if($row['access'] == 1) { echo 'yes'; } elseif ($row['access'] == 0) { echo 'no'; } } ob_end_flush() ?>
the solution easy , class pointed out. forgot select access... instead of username. rookie mistake.
you have write
session_start();
in of files want make use of $_session
.
and select query output username column, have selected one, try
select * admins username = '$sess'
or
select username, access admins username = '$sess'
instead.
what absolutely should learning prepared statements, actual query wide open sql injections.
prepared statement example (from php.net)
if ($stmt = $mysqli->prepare("select district city name=?")) { $stmt->bind_param("s", $city); $stmt->execute(); $stmt->bind_result($district); $stmt->fetch(); $stmt->close(); } $mysqli->close();
Comments
Post a Comment