Reputation: 1727
Ok Im shaking my head at myself as I know this is something obvious but im just not getting it. The query should return 1 result with a matching username and password, then - i just need to check if the column/field "Status" in the row is set to Inactive or Suspended -- If yes then set value of $count and set a $_SESSION value of msg.
As it stands right now the check of Status just doesn't work - Is it because of how I'm comparing the column.field name? $result['Status']?
my query is as follows:
$sql="SELECT * FROM $tbl_name WHERE User_Name='$myusername' and Password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// Verified E-Mail address check
if ($result['Status']=="Inactive") {$count=5;$_SESSION['msg']=="Not Verified";};
Upvotes: 0
Views: 148
Reputation: 594
You should use mysql_fetch_array
or mysql_fetch_assoc
to get an array of data from your query.
$sql="SELECT * FROM $tbl_name WHERE User_Name='$myusername' and Password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// Verified E-Mail address check
$row = mysql_fetch_array($result);
if ($row['Status']=="Inactive") {$count=5;$_SESSION['msg']=="Not Verified";};
Also, my advice is not to use mysql_
functions at all as they are deprecated from version 5.5. Check out mysqli or even better pdo
Upvotes: 3
Reputation: 8174
You need to fetch your data row from the result before you can compare values.
Something like this:
$result = mysql_query($sql);
$data = mysql_fetch_array($result);
if ($data['Status'] == 'Inactive') {
...
}
That being said, there's good reasons not to use mysql_* functions.
See this question for more details:
Why shouldn't I use mysql_* functions in PHP?
Upvotes: 3