I'm having issues posting JS object into a PHP page on submit and then store it into mySQL db.
Here's the script:
var idToDb = [];
var nameToDb = [];
var friendToDb ={};
$('.btn-add').click(function(e){
e.preventDefault();
$(this).toggleClass('btn-info btn-success');
$(this).toggleClass('friend-selected');
$(this).html($(this).html() == "Selected" ? "Add" : "Selected");
addOrRemove(idToDb, $(this).parent().data('id'));
addOrRemove(nameToDb, $(this).parent().data('name'));
friendToDb = _.object(idToDb, nameToDb)
I want to post this array "friendToDb" to a separate PHP page using post after clicking submit button and then store it in mySQL db.
Here's what I'm trying to post in PHP:
<form method="post" action="friend_input.php">
<div id="submitBtnRow" class="row top-plus">
<div class="col-md-12">
<div class="form-group">
<input type="submit" id="submitBtn" class="btn btn-info btn-lg btn-block" value="SUBMIT">Submit</a>
</div>
</div>
</div><!-- /submitBtnRow -->
</form>
And then in friend_input.php, I'm trying to fetch friendToDb and store in mySQL db and this I'm not sure how to do.
Please advice me how this should be done.
Thank you.
$.ajax
?.. – Joke_Sense10 Oct 14 '13 at 16:38friendToDb
is an object not an array.Your code says so. – Joke_Sense10 Oct 14 '13 at 16:44