Note that there are some explanatory texts on larger screens.

plurals
  1. POTextarea on jquery ajax isn't sending to mysql, just input field
    text
    copied!<p>I'm having problems trying to send the value of a textarea to mysql. The value of the input <code>postusername</code> is successfully sent, but not the value of the textarea.</p> <p>And when it was working (I don't know why it stopped), the value was sent in the first time, but if I tried to send another value without refreshing the page, the previous value was sent again and not the new value inserted into textarea.</p> <p>Now, the textarea is returning me an empty value in alert window and is recording only the input <code>postusername</code> in mysql.</p> <pre><code>&lt;form id="newpostform" method="post" style="width:90%;margin-left:auto;margin-right:auto;margin-top:-35px;margin-bottom:10px;font-family:Calibri,Arial;"&gt; &lt;textarea class="editbook" name="newpostcontent"&gt;&lt;/textarea&gt; &lt;div style="margin-top:10px;margin-right:25px;"&gt; &lt;input type="text" value="&lt;?php echo $username0; ?&gt;" name="postusername"&gt; &lt;input class="Button" style="float:right;margin-bottom:10px;margin-left:10px;" type="button" value="Preview"&gt; &lt;input class="Button" style="float:right;margin-bottom:10px;margin-left:10px;" type="button" value="Save draft"&gt; &lt;input id="sendButton" class="Button" style="float:right;margin-bottom:10px;" type="button" value="Send"&gt; &lt;/div&gt; &lt;/form&gt; &lt;script&gt; $(function () { $("input#sendButton").on("click", function () { $.post('newpost.php', $("form#newpostform").serialize(), function (data) { alert($("textarea[name=newpostcontent]").val()); }); }); }); &lt;/script&gt; </code></pre> <p>newpost.php</p> <pre><code>require("../db_info.php"); mysql_query(" INSERT INTO post ( author, content ) VALUES ( '".$_POST['postusername']."', '".$_POST['newpostcontent']."' )" ); </code></pre> <p>If I do, for example:</p> <pre><code>mysql_query(" INSERT INTO post ( author, content ) VALUES ( '".$_POST['postusername']."', 'Why doesn't this work?' )" ); </code></pre> <p>The <code>$_POST['postusername']</code> and the phrase "Why doesn't this work?" is written in the sql correctly.</p> <p>Thanks for your attention.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload