var lid = $('#lid').val();
$.ajax({
type:"post",
url:'../library/lib.php',
data:'action=save_memo&lid'+lid,
success:function(response){
console.log(response);
}
here is the content of lib.php
switch($action){
case 'save_memo':
save_memo($_POST['lid']);
break;}
function save_memo($lid){
$insert = "INSERT INTO tbl_memo (id) VALUES ('$lid')";
if(mysql_query($insert) == false){
$result = array("failed" => $insert)
}else{
$result = array("sucess" => $insert);
echo json_encode($result);
}
the response is success but it doesnt insert into the database
please someone tell me what's wrong, thanks in advance
I believe you're missing an =
sign in your jQuery call:
data:'action=save_memo&lid'+lid
Should be:
data:'action=save_memo&lid='+lid,
Also, check out the big red warning on the mysql_query manual page:
Warning
This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:
- mysqli_query()
- PDO::query()
action
with content save_memo+[lid]
. So when you attempt to retrieve $_POST['lid']
, you will get save_memo
concatenated with whatever the value of #lid
is.$action
before attempting to evaluate it with the switch statement.$lid
is not a variable that was posted with the AJAX request, $action
was.