Note that there are some explanatory texts on larger screens.

plurals
  1. POPhp mysql if/else shorthand
    primarykey
    data
    text
    <p>Can anyone see what is wrong with this shorthand in relation to the problem below?</p> <pre><code>echo "&lt;td&gt;&lt;font size=1 color=#e4d6b5&gt;" . ($row['tier']&lt;$_SESSIONS['tier'] ? "ACCESS DENIED" : $row['contents']) . "&lt;/font&gt;&lt;/td&gt;"; </code></pre> <p>I have two tables in my database: </p> <p>1.) members (id,username,email,password,salt,tier) &lt;-tier is the user's security clearance level. </p> <p>2.) opwire (category,contents,date,userid,seclevel) &lt;-opwire stores user submitted data, userid is just a number that references the user who just submitted data to opwire. Seclevel is how high of a security clearance level (tier) a user needs to see that particular line of submitted data.</p> <p>I'm attempting to get the currently logged in user to be granted or restricted access to 'contents' based on their security tier (referencing member's tier vs opwire's seclevel.) I'm also not entirely confident I'm using http://www.wikihow.com/Create-a-Secure-Login-Script-in-PHP-and-MySQL</p> <p>and I usually get the current user with: </p> <pre><code>$userId = $_SESSION['user_id']; </code></pre> <p>The entire table building php is below. Currently users with any tier can incorrectly view any seclevel contents when their tier should be restricting it.</p> <pre><code>&lt;?php include_once 'functions.php'; include_once 'db_connect.php'; sec_session_start(); if(login_check($mysqli) == true) { $con=mysqli_connect("localhost","mylogin","mypassword","mysqldatabase"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } function getColor($strOption) { switch ($strOption) { case "Case 1": return "#cbae80"; case "Case 2": return "#e59350"; case "Case 3": return "#b7aaa4"; } } $result = mysqli_query($con,"SELECT opwire.*,members.username FROM opwire LEFT JOIN members on opwire.userid=members.id order by date DESC"); echo "&lt;table border='1'&gt; &lt;tr&gt; &lt;th&gt;Category&lt;/th&gt; &lt;th&gt;Contents&lt;/th&gt; &lt;th&gt;Date/Time&lt;/th&gt; &lt;th&gt;Operative&lt;/th&gt; &lt;/tr&gt;"; while($row = mysqli_fetch_array($result)) { echo "&lt;tr&gt;"; echo "&lt;td&gt;&lt;font size=1 color='".getColor($row['category'])."'&gt; " . $row['category'] . "&lt;/font&gt;&lt;/td&gt;"; echo "&lt;td&gt;&lt;font size=1 color=#e4d6b5&gt;" . ($row['tier']&lt;$_SESSIONS['tier'] ? "ACCESS DENIED" : $row['contents']) . "&lt;/font&gt;&lt;/td&gt;"; echo "&lt;td&gt;&lt;font size=1 color=silver&gt;" . $row['date'] . "&lt;/font&gt;&lt;/td&gt;"; echo "&lt;td&gt;&lt;font size=1 color=gold&gt;" . $row['username'] . "&lt;/font&gt;&lt;/td&gt;"; echo "&lt;/tr&gt;"; } echo "&lt;/table&gt;"; mysqli_close($con); } else { echo 'Access to this area requires security clearance. &lt;br/&gt;'; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload