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
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
Related Q & A:
- Why can't I add items to the database?Best solution by Stack Overflow
- Why can't I sign in on messenger but can check my mail?Best solution by Yahoo! Answers
- Why can't I sign into Messenger but I can sign into Mail?Best solution by Yahoo! Answers
- Why can't I access my Yahoo mail even though I can log into Yahoo?Best solution by Yahoo! Answers
- Why can't I receive picture messages but I can send them?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.