jquery - How can I select data from a json object in mysql/php? -


i'm sending json server via jquery's ajax method. here's jquery, , im pretty sure fine:

function stuffs() {     this.fname = document.getelementbyid("fname").value;     this.lname = document.getelementbyid("lname").value;     this.email = document.getelementbyid("email").value;     } $(function() { function ajaxhelper(data){     //console.log(json.stringify(data));     //this returns "{"fname":"mike","lname":"smith","email":"a@a.a"}" expect         $.ajax({         url: 'postdb.php',         type: 'post',         data: {data : json.stringify(data)},         success: function(data) {             console.log(json.stringify(data));             console.log("success");         },         error: function(e) {             console.log(e);         }      }); } $("form").on('submit', function(e){     e.preventdefault();     var data = new stuffs();     ajaxhelper(data);     //window.location = "postdb.php";     });     }); </script> 

i 500 server error. here's php code. (yes i'm sending fname i've preloading database, $con valid didnt share code connect database)

$obj = json_decode($_post['data']);  $sql = "select * testtable fname = \"$obj->{'fname'}\""; $query = $con->query($sql); 

i think sql incorrect due quotes? im stuck.

try using $obj->fname instead of $obj->{'fname'}.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -