Login if condition problem

Good day!

I felt difficulties today because my boss told me that I should separate my html and php code and I should use template to call my html code and used function in template. In opendb function they used mysql_fetch_array, in my old code I used mysql_num_rows how can I adopt the function of opendb for my if condition

here is my code:

error_reporting(E_ERROR | E_WARNING | E_PARSE);


  if (isset($_SESSION['logged_in'])) {

 if (isset($_POST['submit'])) {
	$username = addslashes_gpc($username);
	$password = addslashes_gpc($password);
	$sql_select = "SELECT
	$result = $_DB->opendb($sql_select);

	//$count = $_DB->countdata($result
//as I sain in opendb them used mysql_fetch_array now my problem is what should i put in my if condition and also on my var_dump($result) the output is array(),it means it cannot get or see the data in my database?

		$_SESSION['logged_in'] = true;
	else {
	echo "<center>";
	echo "Wrong Username or Password";
	echo "</center>";

$tpl = new Template('.', 'keep');
$tpl->set_file(array('handle' => 'html/index.html'));
$tpl->parse('handle', array('handle'));

I’m sorry, but the template is not my code and i dont have the rights to change it.

I hope somebody can help me.

What is this opendb function?

opendb function is for the query of the select statement

I mean, is it part of PHP (I can’t find it in the manual), or is it a function/class your company made? What does it do? Does the class have some other method that gives you the number of rows returned?

it is a function.
the function do is

connect if there’s no active connection
then if $result(mysql_query == false)
the error appear
then there is a while loop for mysql_fetch_array
then a foreach for the col name => value

Sorry It’s my first time in function
Thank you for trying to help me

But it’s a function that is part of a class.
A class made by your company, right?

Why don’t you ask your collegues how to use it? Or check out some examples of their work?

Yes, but my boss told me that I have no right to ask my colleagues and saw their codes:(


A weird place you’re working at.

Anyway, if the class doesn’t have any other methods you can use, do some tests. Change your query (just for the test) in a way that no rows are found, and see what the opendb method returns.
Then you can check for that (for example: an empty array?).

I used print_r($result);
and the output is array():frowning:

Ok, so the output is an empty array.
So instead of checking if the number of rows = 0, check if $result is an empty array.

How can i code it sir?Sorry I’m not good in coding because i am beginner

Thank you

PHP: count - Manual

what is the reason why my select statement has no value of array?:frowning:

Because the query doesn’t return any rows?

How can I return rows?

Change the WHERE conditions, or add data to the database that meets your WHERE conditions :slight_smile:

What sir?I have already data in my database:(

What should I replace in my where condition?:frowning:

How would I know?
It’s your data. It’s your code. All I’m saying is that the query you’re running


does not return any rows.
Why? Because the data in machine_problem_rhoda_user does NOT meet the criteria in the WHERE clause of the query.

To check how the query looks like, do an echo of $sql_select.
And to see if it should return any rows, copy and paste the result of that echo in phpMyAdmin.

this is the output when I echo my $sql_select
SELECT username, password FROM machine_problem_rhoda_user WHERE username=‘rhodarose’ AND password=‘20110101’ 0

Ok, and does that table contain a row with username ‘rhodarose’ and password ‘20110101’ ?

Try to run that query in phpMyAdmin.