I have a page that uses TinyMCE to update the contents of the web. when I click the button on the form with ajax post method, I get the contents of my url like this (http://vansolusindo.com/demo2/lapakkemasan/test/test.php?v_content=%3Cp%3Etest+update+data%3C% 2Fp% 3E & save = Submit).
then immediately redirect to the index page of my website. so it makes no .php file for input to the database. My question, how to handle that my page is not redirect to the index page and enter .php pages to insert into the database.
- I've been looking on the internet, there seems to be a setting for his .htaccess file.
The following script .php and my .htaccess.
script test.php:
<!DOCTYPE html>
<html>
<head>
<script>
function umce(){
tinyMCE.triggerSave()
};
function ut(){
$.ajax({
cache: false,
type:'POST',
url:'save.php',
data:"text="+encodeURIComponent(tinyMCE.activeEditor.getContent()),
success: function(data){
alert(1);
}
});
return false;
};
</script>
<script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
<script>tinymce.init({ selector:'textarea' });</script>
</head>
<body>
<form onsubmit='umce();ut(); return false;'>
<textarea id="v_content" name="v_content"></textarea>
<input type="submit" name="save" value="Submit" />
</form>
</body>
</html>
save.php :
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("lapakkemasandb");
$sql="UPDATE t_modules SET content=('$_POST[v_content]') WHERE id_t_modules='3'";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "success to update";
mysql_close($con)
?>
.htaccess :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php