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";};
8
  • 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";}; Commented Jun 5, 2013 at 20:16
  • please tell me password is not in plain text Commented Jun 5, 2013 at 20:16
  • For the moment yes, its all local testing environment, wont be when put up live Commented Jun 5, 2013 at 20:17
  • that's not how to develop security, oh well enjoy being hacked. Commented Jun 5, 2013 at 20:18
  • 2
    @Dagon - Thanks for the useless comment, have great day and enjoy being of no value on this matter Commented Jun 5, 2013 at 20:20

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

2 Comments

It's funny how me and @jcsanyi posted exact same answers and edits at the same time :D
@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.
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?

1 Comment

@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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.