Jquery/ajax login form

Gestart doorWouterp69 reacties108 weergaven

70 berichten · pagina 1 van 5

Wouterp

Lid · Topicstarter

Berichten
1.631
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Heey,

Ik heb hier een probleem met mijn ajax/jquery login form:
letsweb.nl/systemen/overzicht/
Demo:

test
test

Het probleem is dat de ingevoerde gegevens altijd fout zijn.
ajax_login.php

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/require_once"]require_once[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]./includes/connect.php[/COLOR][COLOR= #007700]);[/COLOR]

[COLOR= #FF8000]//get the posted values[/COLOR]
[COLOR= #0000BB]$user_name[/COLOR][COLOR= #007700]=[/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]user_name[/COLOR][COLOR= #007700]];[/COLOR]
[COLOR= #0000BB]$pass[/COLOR][COLOR= #007700]=[/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]password[/COLOR][COLOR= #007700]];[/COLOR]

[COLOR= #FF8000]//now validating the username and password[/COLOR]
[COLOR= #0000BB]$sql[/COLOR][COLOR= #007700]=[/COLOR][COLOR= #DD0000]"SELECT email, wachtwoord FROM LWCMS_accounts WHERE email="[/COLOR][COLOR= #007700].[/COLOR][URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$user_name[/COLOR][COLOR= #007700]).[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$result[/COLOR][COLOR= #007700]=[/COLOR][URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$row[/COLOR][COLOR= #007700]=[/COLOR][URL="http://www.php.net/mysql_fetch_array"]mysql_fetch_array[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$result[/COLOR][COLOR= #007700]);[/COLOR]

[COLOR= #FF8000]//if username exists[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$result[/COLOR][COLOR= #007700])>[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700])
{[/COLOR]
    [COLOR= #FF8000]//compare the password[/COLOR]
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/strcmp"]strcmp[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]password[/COLOR][COLOR= #007700]],[/COLOR][COLOR= #0000BB]$pass[/COLOR][COLOR= #007700])==[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700])
    {[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"yes"[/COLOR][COLOR= #007700];[/COLOR]
        [COLOR= #FF8000]//now set the session from here if needed[/COLOR]
        [COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]email[/COLOR][COLOR= #007700]]=[/COLOR][COLOR= #0000BB]$user_name[/COLOR][COLOR= #007700]; 
    }[/COLOR]
    [URL="http://www.php.net/else"]else[/URL]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"no"[/COLOR][COLOR= #007700]; 
}[/COLOR]
[URL="http://www.php.net/else"]else[/URL]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"no"[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]//Invalid Login[/COLOR]


?>
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Een formulier maken en dan onSubmit="functie(); return false;"

En functie dan een $.post(); neerzetten die de ingevulde waardes ($(#divID).val()wink ophaalt..
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Wouterp schreef:
Ik wil dit:
http://letsweb.nl/systemen/overzicht/
Typ maar gewoon iets in beetje die style. Maar dan werkend P:
Die werkt toch?
0
Wouterp

Lid · Topicstarter

Berichten
1.631
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Nee login gegevens zijn altjd fout..
0
Berichten
264
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
even een off topic vraagje, heb je die zelf gemaakt of ergens gevonden, hij is anders wel nice yummie
0
Wouterp

Lid · Topicstarter

Berichten
1.631
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Die login?
0
Berichten
264
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ja, heb het net opgezocht en vond wel een nieuwere versie, maar dat werkt allemaal wel? Het script kost trouwens 30$...
0
Wouterp

Lid · Topicstarter

Berichten
1.631
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Dat ga ik zoiezo niet doen ik google ook nog even.
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
<script language="javascript">
//  Developed by Roshan Bhattarai 
//  Visit http://roshanbh.com.np for this script and more.
//  This notice MUST stay intact for legal use

$(document).ready(function()
{
    $("#login_form").submit(function()
    {
        //remove all the class add the messagebox classes and start fading
        $("#msgbox").removeClass().addClass(messagebox).text(Validating....).fadeIn(1000);
        //check the username exists or not from ajax
        $.post("ajax_login.php",{ email:$(#username).val(),rand:Math.random() } ,function(data)
        {
          if(data==yes) //if correct login detail
          {
              $("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
            { 
              //add message and change the class of the box and start fading
              $(this).html(Logging in.....).addClass(messageboxok).fadeTo(900,1,
              function()
              { 
                   //redirect to secure page
                 document.location=secure.php;
              });
              
            });
          }
          else 
          {
              $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
            { 
              //add message and change the class of the box and start fading
              $(this).html(Your login detail sucks...).addClass(messageboxerror).fadeTo(900,1);
            });        
          }
                
        });
         return false; //not to post the  form physically
    });
    //now call the ajax also focus move from 
    $("#password").blur(function()
    {
        $("#login_form").trigger(submit);
    });
});
</script>


Staat er. Kan je btj ombouwen.
0
Berichten
5.957
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
*edit*

Nvm.
0
Wouterp

Lid · Topicstarter

Berichten
1.631
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Antonn schreef:
<script language="javascript">
//  Developed by Roshan Bhattarai 
//  Visit http://roshanbh.com.np for this script and more.
//  This notice MUST stay intact for legal use

$(document).ready(function()
{
    $("#login_form").submit(function()
    {
        //remove all the class add the messagebox classes and start fading
        $("#msgbox").removeClass().addClass(messagebox).text(Validating....).fadeIn(1000);
        //check the username exists or not from ajax
        $.post("ajax_login.php",{ email:$(#username).val(),rand:Math.random() } ,function(data)
        {
          if(data==yes) //if correct login detail
          {
              $("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
            { 
              //add message and change the class of the box and start fading
              $(this).html(Logging in.....).addClass(messageboxok).fadeTo(900,1,
              function()
              { 
                   //redirect to secure page
                 document.location=secure.php;
              });
              
            });
          }
          else 
          {
              $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
            { 
              //add message and change the class of the box and start fading
              $(this).html(Your login detail sucks...).addClass(messageboxerror).fadeTo(900,1);
            });        
          }
                
        });
         return false; //not to post the  form physically
    });
    //now call the ajax also focus move from 
    $("#password").blur(function()
    {
        $("#login_form").trigger(submit);
    });
});
</script>
Staat er. Kan je btj ombouwen.

Die gebruik ik nu maar werkt niet...
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Lekker duidelijk maar weer..... nopompomnopompomnopompom
0
Wouterp

Lid · Topicstarter

Berichten
1.631
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Het wachtwoord is altijd volgens dat ding
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Wouterp schreef:
Het wachtwoord is altijd volgens dat ding
Lekker Nederlands maar weer :/

En by the way: Alles valt te debuggen.
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren