I tried to save a HTML and also Javascript codes to Database by Ajax, but don't know how to optimize this way. I can't just write all codes like Strings for the variable. Do you have another idea to make it simpler ?
<script type="text/javascript">
$(document).ready(function(){
$("#add_code").click(function(){
var addCode = "Here is Javascript code";
$.get("includes/dashboard/addcode.php", {addCode:addCode
},function(data){
});
});
});
</script>
And this is the addcode.php
<?php
require('database/connect_database.php');
session_start();
$addCode = $_GET['addCode'];
$codename = $_SESSION['codename'];
$stmt = $pdo->prepare("INSERT INTO code (codename, w_code) VALUES ('$codename','$addCode')");
$stmt->execute();
?>