Advanced Search

Results 1 to 5 of 5

Thread: Login if condition problem

  1. #1
    Join Date
    Jul 2010
    Posts
    228
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default 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:
    PHP 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.

  2. #2
    Join Date
    Feb 2008
    Posts
    81
    Thanks
    8
    Thanked 5 Times in 5 Posts

    Default

    Can you try:

    PHP Code:
    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:

    PHP Code:
    if(count($result) == 1) {

    // .........



  3. #3
    Join Date
    Jul 2010
    Posts
    228
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default

    the output of print_r($result); is array():(

  4. #4
    Join Date
    Feb 2008
    Posts
    81
    Thanks
    8
    Thanked 5 Times in 5 Posts

    Default

    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?

  5. #5
    Join Date
    Jul 2010
    Posts
    228
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default

    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •