I have a simple div with input fields to insert data for team data
<div> <label>Register</label> <input type="text" name="nt" placeholder="Team Name"> <label>Team</label> <input type="text" name="n1" placeholder="Steam username"> <input type="text" name="n2" placeholder="Steam username"> <input type="text" name="n3" placeholder="Steam username"> <input type="text" name="n4" placeholder="Steam username"> <input type="submit" id="sbutton"></input> </div> Then i use Jquery to collect that data and send it to my php file.
$('#sbutton').click(function(){ var sdata=[]; $(this).parent().children("input[type=text]").each(function(index,value){ index = $(this).attr("name"); value = $(this).val(); sdata[index]=value; }); console.log(sdata); $.post('php/team.php',sdata, function(returnedData){ console.log(returnedData); }); }); In my php file i process that data,but the problem is,that is not passed by the jquery function.My php:
<?php session_start(); include_once "functions.php"; print_r($_POST); if(!isset($_POST["nt"])) die("Usernames not set");?> My console log:
[nt: "asdasd", n1: "asdasd", n2: "asdasd", n3: "asdasd", n4: "asdasd"] jquery-2.1.4.min.js:4 XHR finished loading: POST "http://localhost/tournament/php/team.php".k.cors.a.crossDomain.send @ jquery-2.1.4.min.js:4n.extend.ajax @ jquery-2.1.4.min.js:4n (anonymousfunction) @ jquery-2.1.4.min.js:4(anonymous function) @ main_page.php:31n.event.dispatch @ jquery-2.1.4.min.js:3r.handle @ jquery-2.1.4.min.js:3 main_page.php:33 Array ( ) Usernames not set Why is this happening?