user1072910
user1072910

Reputation: 261

PHP won't return a response

It's probably something really basic but I've been at it for a while and it's not jumping out at me and I guess I'm tired...please help.

I'm trying to create a simple login html page, read it using jquery/ajax and have php verify it. Here are the 2 pieces the javascript/jquery and the php. While firebug seems to correctly report that "message" is being set, nothing comes back as response...what am I doing incorrectly? And if php did report an error, where do I look for it?


login.js

$(document).ready(function(){  
    $('#loginForm').submit(function(){  
        var usern=$('#username').val();  
        var pword=$('#password').val();  
       $.ajax({  
            url: 'mylogin.php',  
            data: 'action=login&usern='+usern+'&pword='+pword,  
            dataType: 'json',  
            type: 'post',  
            success: function (j) {  
                $('#loginmessage').html(j.msg);  
            },  
       });  
    });  
});`    

mylogin.php

<?php   
    $username=$_POST['username'];  
    $password=$_POST['password'];  
    $retval['msg']="in mylogin.php";  
    fb($retval,"return output from login");  
    echo json_encode($retval);  
?>

Upvotes: 2

Views: 169

Answers (3)

Taz
Taz

Reputation: 1303

You're setting the post variables with the names usern and pword then trying to access them with username and password

Upvotes: 2

Matt Seymour
Matt Seymour

Reputation: 9395

You are using username and password as the post variables names in the PHP code when you are passing the variable names through as usern and pword in your jquery post.

It should look something like

<?php   
    $username=$_POST['usern'];  
    $password=$_POST['pword'];
?>

It is important when passing variables to use a standard naming convention, it will help reduce the chance of these issues occuring.

Upvotes: 1

Gautam
Gautam

Reputation: 7958

Its very simple you are posting your username as usern and password aspword

So it should be

<?php   
    $username=$_POST['usern'];  
    $password=$_POST['pword'];  

Upvotes: 8

Related Questions