0

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";};
DMSJax
  • 1,709
  • 4
  • 22
  • 35
  • The last code line has an error i have corrected here, but is not the problem: `// Verified E-Mail address check if ($result['Status']=="Inactive") {$count=5;$_SESSION['msg']="Not Verified";};` – DMSJax Jun 05 '13 at 20:16
  • please tell me password is not in plain text –  Jun 05 '13 at 20:16
  • For the moment yes, its all local testing environment, wont be when put up live – DMSJax Jun 05 '13 at 20:17
  • that's not how to develop security, oh well enjoy being hacked. –  Jun 05 '13 at 20:18
  • are you sure its only returning one row? – stackErr Jun 05 '13 at 20:19
  • 2
    @Dagon - Thanks for the useless comment, have great day and enjoy being of no value on this matter – DMSJax Jun 05 '13 at 20:20
  • eAfter you get the $results you need to fetch the rows. `while ($row = mysql_fetch_array($result)) { do something with $row['Status'] }` I'll leave for somebody that has time to explain why you shouldnt use `mysql_*` functions to ceate an answer. Also if it returns just 1 row you dont need the while loop – Hugo Delsing Jun 05 '13 at 20:21
  • @user1160022 yes, there is a check for that later in script, but the table only has 1 record in it, so it dont have much of a choice but return 1 record – DMSJax Jun 05 '13 at 20:21

2 Answers2

3

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?

Community
  • 1
  • 1
jcsanyi
  • 8,133
  • 2
  • 29
  • 52
  • @jcsanyi Also correct JC, in so far as the mysql_* I'm literally only about 2 weeks into learning/re-learning PHP after about a 6 year absence from that language. So, Im learning by examples, edits and then doing my own, some examples online are still using the mysql_* instead of mysqli_*, but i will work to correct the bad code, thanks for pointing it out. – DMSJax Jun 07 '13 at 13:42
3

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

Goran Lepur
  • 594
  • 1
  • 4
  • 15
  • It's funny how me and @jcsanyi posted exact same answers and edits at the same time :D – Goran Lepur Jun 05 '13 at 20:33
  • @GoranLepur You know I tried that at one point and it didn't work, but went back and tried it again after the answers and got it working. So, I don't know, maybe I had something typed wrong - but in any case the answer is correct and thank you fro being helpful. – DMSJax Jun 07 '13 at 13:39