I'm updating a messaging system on my website, and I can't figure out why the following chunk of code isn't working At All:
function sendReply(id,from,to)
{
var subject = document.getElementById("subject").innerHTML;
var body = document.getElementById("body").innerHTML;
var xmlhttp;
if (id.length==0) {
document.getElementById("userMessagingBackground").innerHTML = "";
return;
}
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET", "sendOutReply.php?from=" + from + "&to=" + to + "&subject=" + subject + "&body=" + body, true);
xmlhttp.send();
document.getElementById("userMessagingBackground").style.display = "none";
}
So...Uh...Is there anything wrong with this? If not...Here's the PHP part:
<?php
$to = $_GET['to'];
$dbc = mysqli_connect(Database Connection Stuff);
$username = $_GET['user'];
if (!empty($_GET['body'])) {
$sub = $_GET['subject'];
$body = "Sent by $username:
---
"
. $_GET['body'] . "
------------------------
"
. $receivedMsg;
$STM = "INSERT INTO messagingTable
(new, sender, receiver, subject, message, sentDate)
VALUES ('1', '$username', '$to', 'RE: $subject', '$body', NOW())";
$sendMessage = mysqli_query($dbc, $STM);
$findReceiver = "SELECT * FROM usersTable WHERE username = '$to'";
$getTo = mysqli_query($dbc,$findReceiver);
$toRow = mysqli_fetch_array($getTo);
if ($toRow['emailOnPm'] == 1) {
mail($toRow['email'],$sub,$body, "From: AllThemGames.com");
}
}
?>