0

I'm trying to send some data to PHP file but jQuery don't even run my PHP file. Just for the sake of testing I echo some text but I couldn't see any output. This is my code:

jquery :

.
.
.

$("#addFolder").click(function(){
    $(".folders").append("<p class='folder'>This is first folder<input type='checkbox' name='checkFolder'></p>");
    $data = {'id':document.getElementById('id').value, 'text':document.getElementById('text').value};
    $.post('addFolder.php', $data);
});

addFolder.php :

<?php

include 'connect.php';
include 'functions.php';

$id = $_POST['id'];
$text = $_POST['text'];

session_start();
$user = $_SESSION['user'];

$userID = mysql_query("select id from users where username = '$user'")
$iduser = mysql_result($userID, 0)

mysql_query("insert into users_folders values ('$iduser', '$id') where id = '$iduser'") or die(mysql_error());

?>
4

2 回答 2

4
$.post('addFolder.php', data);

should be

$.post('addFolder.php', $data);

There is a typo when you are passing parameters data

Problem in your addFolder.php following line :

mysql_query("insert into users_folders values ('$iduser', '$id') 
             where id = '$iduser'") or die(mysql_error());
于 2013-08-05T09:21:05.160 回答
1

check this

$.post('addFolder.php', data);
//data replace $data like =>  $.post('addFolder.php', $data);

so now

$("#addFolder").click(function(){
     $(".folders").append("<p class='folder'>This is first folder<input type='checkbox' name='checkFolder'></p>");
     $data = {'id':document.getElementById('id').value, 'text':document.getElementById('text').value};
     $.post('addFolder.php', $data);
});
于 2013-08-05T09:20:43.067 回答