Log in

View Full Version : Login if condition problem



rhodarose
05-11-2011, 07:00 AM
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:


<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);
include('includes/config.sender.php');
include('includes/template.inc');


session_start();

if (isset($_SESSION['logged_in'])) {
header('Location:machine1.php');
die();
}


if (isset($_POST['submit'])) {
$username=$_POST['username'];
$password=$_POST['password'];

$username = addslashes_gpc($username);
$password = addslashes_gpc($password);


$sql_select = "SELECT
username,
password
FROM
machine_problem_rhoda_user
WHERE
username='$username'
AND
password='$password'
";

$result = $_DB->opendb($sql_select);

var_dump($result);


//var_dump($sql_select);

//$result=mysql_query($sql_select);
//$count = $_DB->countdata($result

//$count=mysql_num_rows($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?

if($count==1){
$_SESSION['logged_in'] = true;
header("location:machine1.php");
}
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'));
$tpl->p('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.

midhul
05-11-2011, 07:35 AM
Can you try:



print_r($result);


so that we can know if it's actually accessing the database, and returning an array of values.

If it is returning a valid array with the data you want, then probably you can use the count(); function in your if condition:



if(count($result) == 1) {

// .........

}

rhodarose
05-11-2011, 07:42 AM
the output of print_r($result); is array():(

midhul
05-11-2011, 08:03 AM
Well then, that means opendb is not fetching your DB data into an array.

Can you somehow show us what exactly the template is doing?

rhodarose
05-11-2011, 08:58 AM
opendb is a function

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