How can I deserialize JSON {name, value} in C#?

Why can't I insert text values into the database?

  • form: <form method="post" action=''> <textarea style="width:728px; font-size:14px; height:60px; font-weight:bold; resize:none;" name="content" id="content" ></textarea><br /> <textarea style="width:728px; font-size:14px; height:40px; font-weight:bold; resize:none;" name="source" id="source" ></textarea><br /> <input type="submit" value="Post" name="submit" class="submit_button"/> </form> script : <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function() { $(".submit_button").click(function() { var message = $('#content').val(); var textcontents = $("#source").val(); $.ajax({ async: true, type: "POST", url: './ajtest.php', data: {tc:message,ts:textcontents}, dataType: 'json', cache: true, contentType: false, processData:false, }); }); }); </script> PHP <?php $tc=$_POST['tc']; $ts=$_POST['ts']; require"./connect.php"; mysql_query("INSERT INTO oxl VALUES('','$tc','$ts','')"); ?> What are the errors here ?

  • Answer:

    If you look at the data being POSTed in Chrome DevTool network panel, it's shown as "[object Object]", which means it's an JavaScript object encoded wrong instead of a properly encoded x-www-form-encoded byte stream that PHP's $_POST expects. Add to the param contentType: "application/x-www-form-urlencoded", and see the difference.

Ryan Gao at Quora Visit the source

Was this solution helpful to you?

Other answers

You should try with sprintf and refrain from using the variables directly in the query. You can check sprintf syntax on http://php.net

Bhavin Joshi

It works when I removed dataType: 'json', contentType: false, processData:false,

Prakash Bhatia

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.