I have a problem in PHP/Jquery.
What I want : I have a page in PHP that I use to change article in my website. The page contain text and textarea in PHP plus 1 button. When I enter that page, the page fill any text form and text area automatically from database. I use that form to write some article that contain about 200-800 character. The article contain some Line breaks using Enter Key. When I press My save button, the text in textarea and text forms was store in SQL database with VARCHAR/TEXT type to replace the OLD article. My Save button just reload the same page and save the text in textarea using PHP. I just successfully make that dynamically so when I press the save button, the text in textarea and any other form doesn't change back to old article.
The problem : When text in textarea have a line breaks from enter key (not from wordwrap), the text didn't want to fill any text form and textarea when I access the page from save button or just from other page. So my text in form suddenly disapear when I reload the page. But the text successfully save with the line breaks too in SQL when I check with PHP my admin. This problem doesnt came out when I write without any line breaks.
This is PHP code that handle saving and reading database.
$judul = $_POST['inputEditJudul'];
$jenis = $_POST['inputEditJenis'];
$isiArt = $_POST['inputEditIsi'];
date_default_timezone_set('Indonesia/Jakarta');
$tanggal = date('Y-m-d');
if(isset($_POST['btn_Save'])) {
$sql = "UPDATE artikel
SET judul='".$judul."', jenis_artikel='".$jenis."', isi_artikel='".$isiArt."', tanggal= CAST('".$tanggal."'AS DATE)
WHERE id=".$_GET['id'].";";
mysql_query($sql,$link);
}
$sql = "SELECT * FROM artikel WHERE id=".$_GET['id'].";";
$result = mysql_query($sql, $link);
$row = mysql_fetch_array($result);
This is the jquery script that handle filling the form in same page.
<script>
$(document).ready(function(){
$("#inputEditJudul").val("<?php echo ($row['judul']) ?>");
$("#inputEditIsi").val("<?php echo nl2br($row['isi_artikel']) ?>");
var jenisArt = <?php echo $row['jenis_artikel'] ?>;
if ( jenisArt == 1){
$("#inputEditJenis").val("1");
} else {
$("#inputEditJenis").val("2");
};
});
</script>
This is the text area in my form
....
<div class="form-group">
<label for="inputEditIsi">Isi Artikel</label>
<textarea class="form-control" id="inputEditIsi" name="inputEditIsi" rows="10" maxlength="800"></textarea>
</div>
....
If possible, please just use PHP/Jquery. I dont know anyhing about ajax.
Sorry for my bad English. I'm still newbie in here.
Thank you