Jump to content

Problem with login in php with javascript modalbox


ahidam

Recommended Posts

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.

 

url to the project are:

http://nettbutikk.site11.com/madiha2/

 

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>

 

***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();

?>  

 

 

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.;   
   
      //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();
   });         
   
});

I did a "show source" on your page. Before you go any further, clean up the HTML.  No web page can have more than one <html><head></head><body></body></html> sequence in it. Your main page has at least 2.

 

You are, obviously, using jQuery to do most of the Javascript work, but why don't you use Dialog widget from the jQuery UI to do the rest of the work?

 

Ken

Thanks for replying me.

 

i have tried to clean up my  html code. I had  two of </head> which i have removed now.

I have unfortunately not so much time that I can experiment more suggestions. The UI widget I have probably put together, so that the links and input fields work with php. And that requires much time for me, since i am not so good in using javascript. or do you have any other suggestions? if you can see whats wrong with my existing code so that I can use it or if you have an example of login form in jquerry UI? I would be very grateful for that.

:( :(

 

I did a "show source" on your page. Before you go any further, clean up the HTML.  No web page can have more than one <html><head></head><body></body></html> sequence in it. Your main page has at least 2.

 

You are, obviously, using jQuery to do most of the Javascript work, but why don't you use Dialog widget from the jQuery UI to do the rest of the work?

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.