URGENT: Problem with login in php with javascript modalbox

Discussion in 'PHP' started by ahidam, May 9, 2010.

  1. #1
    I have created a modal login to my php project.
    Modalen display correctly, but the problem is that when the login button is pressed it goes to the page I have to refer to, but it does not come up any information / echo message.

    When I test adding the code to a blank page, without javascript Modalbox, then it works perfectly. But as soon as I put the login table and the code in Modalen the php coding is not working anymore. I do not know what's wrong with it, whether it's because of modalbox or, I need to make the code slightly so that it adapts modalbox?

    The only feature works here when I click the login button with empty input fields. Then I get error message that the fields must be filled. Otherwise it does not look like the code works in modalbox.

    It very urgent. Hoping for a quick response

    Thanks in advance.

    ****HTML CODE****
    
    index.php
    
    <!--Start of customer login-->
    <form name="form1" method="post" action="phpFiler/min_konto.php">
    
    <div id="boxes">
    
       
    <!-- Start of Login Dialog --> 
    <div id="dialog1" class="window">
    <div id="close"> <input type="image" value="X" class="close" src="image/X.png" /></div>
      <div class="d-header">
    
      <div id="login_heading"></div>
      <input name="brukernavn" type="text" id="brukernavn" onclick="this.value=''">
      <input name="passord" type="password" id="passord" onclick="this.value=''">
    </div>
    <div class="d-blank">
      <table width="356" border="0" cellspacing="0" cellpadding="0">
      <tr>
      <td  align="left" width="6"></td>
        <td  align="left">
        <input type="checkbox" name="husk">
    <font size="2">Husk meg<br />    <INPUT type="button" value="Glemt passord" onClick="window.location.href='glemtpassord.htm'"> <br /><a href="leggtilbrukere.php" name="modal">Registrer</a></td>
    <td  align="left" width="10"></td>
        <td align="left"><input type="submit" name="submit" value="Login" src="image/loginBtn.png">  </td>
      </tr>
    </table>
    
      </div>
      <div class="d-login"><br/>    </div>
    </div>
    <!-- End of Login Dialog --> 
    <!-- Mask to cover the whole screen -->
      <div id="mask"></div>
    </div>
    </form>
    <!-- Mask to cover the whole screen -->
      <div id="mask"></div>
    </div>
    <div style="clear:both;"></div>
    
    </div>
    Code (markup):
    ***PHP CODE****
    
    min_konto.php
    
    <?php 
    
    $connect = mysql_connect(XXXXX);
    mysql_select_db('XXXXX',$connect);
    
    function displayLogin(){
       global $logged_in;
       if($logged_in){
          echo "<h1>Logged In!</h1>";
          echo "Welcome <b>$_SESSION[brukernavn]</b>, you are logged in. <a href=\"loggut.php\">Logout</a>";
       }
       else{
    ?>
    
    <table width="300" border="0" align="center" cellpadding="0" cellspacing="1">
    <tr>
    <td><form name="form1" method="post" action="">
    <table width="100%" border="0" cellspacing="1" cellpadding="3">
    <tr>
    <td colspan="3"><center><strong>Login </strong></center></td>
    </tr>
    <tr>
    <td width="71">Brukernavn</td>
    <td width="6">:</td>
    <td width="301"><input name="brukernavn" type="text" id="brukernavn" <?php if(isset($_COOKIE['cooknavn'])) echo 'value="'.$_COOKIE['cooknavn'].'"';?></td>
    </tr>
    <tr>
    <td>Passord</td>
    <td>:</td>
    <td><input name="passord" type="password" id="passord" <?php if(isset($_COOKIE['cookpass'])) echo 'value="'.$_COOKIE['cookpass'].'"';?> /></td>
    </tr>
    <tr>
    <td colspan="2" align="left"><input type="checkbox" name="husk">
    <font size="2">Husk meg</td>
    <td colspan="3" align="center"><input type="submit" name="submit" value="Login"> <a href="glemtpassord.php">Glemt passord?</a>
    </tr>
    </table>
    </form>
    </td>
    </tr>
    </table>
    <?php
       }
       }
    $brukernavn = trim($_REQUEST['brukernavn']);
    $ukryptert_passord = trim($_REQUEST['passord']);
    $passord =md5(trim($_REQUEST['passord']));
    
    if (isset($_REQUEST[submit]))
    {
       /* ser om alt er skrevet inn */
       if(!$_POST['brukernavn'] || !$_POST['passord']){
          die("Brukernavn og Passord må være utfylt!<br /> <a href='login.php'>Tilbake</a>");
       }
      
      $sql = "SELECT * FROM login WHERE BRUKERNAVN LIKE '".$brukernavn."' AND PASSORD LIKE '".$passord."'";
    
       
       $resultat = mysql_query($sql);
       
       $antall = mysql_num_rows($resultat);
    function checkLogin(){
       /* Check if user has been remembered */
       if(isset($_COOKIE['cooknavn']) && isset($_COOKIE['cookpass'])){
          $_SESSION['brukernavn'] = $_COOKIE['cooknavn'];
          $_SESSION['passord'] = $_COOKIE['cookpass'];
       }
    
       /* Username and password have been set */
       if(isset($_SESSION['brukernavn']) && isset($_SESSION['passord'])){
          /* Confirm that username and password are valid */
          if(confirmUser($_SESSION['brukernavn'], $_SESSION['passord']) != 0){
             /* Variables are incorrect, user not logged in */
             unset($_SESSION['brukernavn']);
             unset($_SESSION['passord']);
             return false;
          }
          return true;
       }
       /* User not logged in */
       else{
          return false;
       }
    }
    
    //Husk meg funksjon i 1 dag.
    
       if(isset($_POST['husk'])){
           setcookie("cooknavn", $_SESSION['BRUKERNAVN'], time()+3600*24, "/");
           setcookie("cookpass", $ukryptert_passord, time()+3600*24, "/");
        } 
    
    //Magic quotes 
    //echo "Er magic quotes satt? : ".get_magic_quotes_gpc()."<br/>";
        
        if (!get_magic_quotes_gpc()) 
        {
            $brukernavn = mysql_escape_string($brukernavn);
            $passord = mysql_escape_string($passord);
        }
        
        $sqlsetning = "DELETE * FROM login WHERE BRUKERNAVN = '$brukernavn' AND PASSORD> '$passord'";
        
    }
    $logged_in = checkLogin();
    
    ?>  
    Code (markup):
    JAVASCRIPT - MODAL
    //LOGIN MODAL
    $(document).ready(function() {   
    
       //select all the a tag with name equal to modal
       $('a[name=modal]').click(function(e) {
          //Cancel the link behavior
          e.preventDefault();
         
          //Get the A tag
          var id = $(this).attr('href');
       
          //Get the screen height and width
          var maskHeight = $(document).height();
          var maskWidth = $(window).width();
       
          //Set heigth and width to mask to fill up the whole screen
          $('#mask').css({'width':maskWidth,'height':maskHeight});
         
          //transition effect   
         
          //Den fader in til helt blank side   
          /*$('#mask').fadeIn(1000);   */
         
          //Den fader ut til lys side
          $('#mask').fadeTo("slow",0.8);   
       
          //Get the window height and width
          var winH = $(window).height();
          var winW = $(window).width();
                 
          //Set the popup window to center
          $(id).css('top',  winH/2-$(id).height()/2);
          $(id).css('left', winW/2-$(id).width()/2);
       
          //transition effect
          $(id).fadeIn(2000);
       
       });
       
       //if close button is clicked
       $('.window .close').click(function (e) {
          e.preventDefault();
          $(this).hide();
          $('.window').hide();
       });   
       
       /*$('.window.reg').click(function (e) {
       
          windows.location('phpFiler/registrer.php');
        });
       */
    
         
       //if mask is clicked
       $('#mask').click(function () {
          $(this).hide();
          $('.window').hide();
       });         
       
    });
    Code (markup):
     
    ahidam, May 9, 2010 IP
  2. Sky AK47

    Sky AK47 Member

    Messages:
    298
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    45
    #2
    Simply because you're not calling the displayLogin function, nowhere in min_konto.php.
    Also I'd advice you to change your code;
    - SQL injections will love your code.
    - You ain't checking if the user/pass exists, you do have "$antall = mysql_num_rows($resultat);" but no if statement.
     
    Sky AK47, May 9, 2010 IP