Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try removing the <code>encodeURI()</code> function from your javascript, like so:</p> <pre><code>var whatIsNowForbidden = $("#forbiddenField").text(); </code></pre> <p>I made a fiddle to test this and javascript's <code>encodeURI()</code> function doesn't seem to translate the new lines made in the paragraph to <code>%0A</code>, like we were expecting to.</p> <p>By removing the function <code>encodeURI()</code> PHP should be able to save the text, including new lines, to the database. And then, PHP's <code>nl2br()</code> should transform the new lines into <code>&lt;br /&gt;</code> tag's with no problem.</p> <p>The fiddle is available here: <a href="http://jsfiddle.net/LN7QC/" rel="nofollow">http://jsfiddle.net/LN7QC/</a></p> <p><strong>Final answer:</strong> use <code>&lt;textarea&gt;</code></p> <p>The jQuery:</p> <pre><code>$("#forbiddenField").blur(function(){ var whatIsNowForbidden = $("#forbiddenField").val(); $.ajax({ type: "POST", url: "updateForbidden.php", data: "forbiddenStuff="+ whatIsNowForbidden, success: function(){ } }); }); </code></pre> <p>adding to database:</p> <pre><code>&lt;?php include('connect.php'); if($_POST['forbiddenStuff']){ $forbiddenInput = $_POST['forbiddenStuff']; } If($forbiddenInput){ mysql_query("SET NAMES 'utf8'"); $changeDataInDB = "UPDATE heroes_and_helpers SET forbidden='$forbiddenInput' WHERE name ='sabina'"; mysql_query($changeDataInDB); } ?&gt; </code></pre> <p>fetching from database:</p> <pre><code> mysql_query("SET NAMES 'utf8'"); $fetchForbidden = mysql_query("SELECT * FROM heroes_and_helpers WHERE name='sabina'"); if (!$fetchForbidden) { die('Ngt ar fel: ' . mysql_error()); } $whatIsForbidden = mysql_fetch_array($fetchForbidden); $forbidden = $whatIsForbidden['forbidden']; </code></pre> <p>on the site:</p> <pre><code>&lt;textarea id="forbiddenField" style="width: 450px; height: 500px;"&gt;&lt;?php echo $forbidden; ?&gt;&lt;/textarea&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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