I've been trying to set a value from my mysql server table field equal too the $_SESSION["mypermissions"] session variable. Whatever I try it comes up blank though or with a value 0. I feel like this is probably a stupid question and there's a simple solution but nothing seems to be working. Here is my code so far, look near the bottom for the sql query in question.
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="comproject"; // Database name
$tbl_name="members"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
session_start();
$_SESSION["myusername"] = $myusername;
$sql = "SELECT permissions FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$_SESSION["mypermissions"] = mysql_query($sql);
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>
$_SESSION["mypermissions"] = mysql_query($sql);, you are assigning a resource to the session variable. Instead, you want to get a result from the query first.SELECT *and thenSELECT permissions, but theWHEREcondition is the same. You could extract the permissions from the result of the first query.