0

I am trying to post a data on run time and I want to see this data same time. But I don't understand clearly how can I do. I think my problem is I could not choose the element correctly. What is wrong on my code ? Thanks all from now :)

My Error is : Notice: Undefined index: username in C:\wamp\www\eva\check.php on line 3

Line 3 : echo $username = $_POST["username"];

form.php

<html>
<head>
    <title>jQuery</title>
</head>
<body>
    <div class="formwrapper">
        <form method="post" action="" name="form">
            <input type="text" id="rname" class="inputa" name="uname" placeholder="Username">
            <div id="feedback"></div>
        </form>
    </div>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
    <script src="myScript.js"></script>
</body>
</html>

check.php

<?php

    echo $username = $_POST["uname"];

?>

myScript.js

$(document).ready(function() {

    $("#feedback").load("check.php").show();

    $("#rname").keyup(function() {

        $.post("check.php", { username: uname.value },
        function(result){

            $("#feedback").html(result).show();

        })

    });

});
Community
  • 1
  • 1
Brown
  • 27
  • 7

1 Answers1

0

You are POSTing the value as username and trying to retrieve it as uname. Rename your key in PHP:

$username = $_POST['username']

It's probably also a good idea to check if the value exists and return a nice error message instead of letting your code fail.

Jon Koops
  • 8,801
  • 6
  • 29
  • 51