I'm trying to store the editable content of a Div in an SQL database. However from what I can tell isset($_POST["des"])
never returns true.
(I haven't done much website coding so I am probably missing something quite fundamental/trivial)
overview_page.php:
<?php session_start();
include_once("php_includes/check_login_status.php");
?>
<?php
if(isset($_POST["des"]))
{
echo "Inside IF statement";
include_once("php_includes/db_conx.php");
$des = mysqli_real_escape_string($db_conx, $_POST['des']);
$sql = "UPDATE users SET project_description='$des' WHERE username='$log_username'";
}
?>
<!DOCTYPE html>
<html>
<head>
<script src="js/main.js"></script> <!--Points to external java script file-->
<script src="js/ajax.js"></script> <!--Points to external java script file-->
<script type="text/javascript">
function save_description()
{
var des = _("project_description").value;
var ajax = ajaxObj("POST", "overview_page.php");
//ajax.onreadystatechange = function() sorry this one shouldn't be here
ajax.send("des="+des);
}
</script>
</head>
<body>
<?php include_once("template_pagetop.php"); ?>
<div id="pageMiddle">
<div id="left_window">
<div id="project_description" name="project_description" contentEditable="true">
Please enter project description...
</div>
<center>
<button id="save" onclick="save_description()">Save</button>
</center>
</div>
</div>
</body>
</html>
and external scripts:
ajax.js:
function ajaxObj( meth, url ) {
var x = new XMLHttpRequest();
x.open( meth, url, true );
x.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
return x;
}
function ajaxReturn(x){
if(x.readyState == 4 && x.status == 200){
return true;
}}
main.js:
function _(x)
{
return document.getElementById(x);
}