I am quite new to PHP and mySQL. I am trying to check if the session's user is an admin.
Surely there is a better way to do this.
Here is a snippet of the code that I think has incorrect logic:
$conn = mysql_connect("$host", "$username", "$my_gateway")or die("Connection failed. If you received this error it is the webhost's fault, not yours. Please retry. <a href = 'index.php'> Home </a>"); mysql_select_db("$db")or die("Connection failed. If you received this error, it is mySQL's fault, not yours. Please retry. <a href = 'index.php'> Home </a> "); $sql = "SELECT * FROM PREREG WHERE admin=1 AND emaad='$user1'"; $result = mysql_query($sql, $conn); if($result) { echo "You are an admin!"; }
Alright. So, there are two central properties I am attempting to verify.
1) admin. If the user is an admin, the property will be manually set by the owner of the database to 1. Otherwise it remains 0.
2) emaad. This is the email that was registered into the session.
Now I'm attempting to find the row inside the table that contains the registered email and check if admin=1. If so, echo 'You are an admin!'.
I did not receive an error. I just get the elements originally inside the page.
My registered user is however an admin, and I do not get this
echomessage.
$user1 is defined as
$_SESSION['input_use'];.
Any help?
Thanks in advance.