The .get() requests were doing just fine until I added mysql into the mix, and I debugged the SQL and made sure it was connecting perfectly and everything but its still not working. If someone can tell me where I'm going wrong that would be great.
JavaScript -
if (command !== '') {
term.echo('Waiting on response from server...');
if (command.indexOf(' ') !== -1) {
var ext_start = command.indexOf(' ');
var ext_end = command.length;
var ext = command.substr(ext_start, ext_end);
$.get('response.php', {command: command, ext: ext}, function(data) {
term.echo("Response from command: " + command + "->" + data);
});
}
else {
$.get('response.php', {command: command}, function(data) {
term.echo("Response from command: " + command + "->" + data);
});
}
try {
var result = window.eval(command);
if (result !== undefined) {
term.echo(new String(result));
}
} catch(e) {
//term.error(new String(e));
}
} else {
term.echo('');
}
response.php -
<?php
if (isset($_GET['command'])) {
require 'config.php';
$cmd = $_GET['command'];
if (isset($_GET['ext'])) {
//Things to do if a double command was executed (e.g. !screenshot botname)
$ext = $_GET['ext'];
echo "Double Command Successful.";
}
else {
//Things to do if just a single command was executed (e.g. !info)
$query = mysqli_query($connect, "SELECT * FROM commands WHERE command='$cmd'");
$numrows = mysqli_num_rows($query);
if ($numrows !== 1) {
//If the command doesn't exist
echo "Command non-existant";
}
else {
//If the command does exist*/
mysqli_query($connect, "UPDATE commands SET status=1 WHERE command='$cmd'");
echo "Command does exist";
}
}
}
else {
echo "Error";
}
?>
Oh please don't post/comment "Your code is vulnerable to SQL injection, bla bla bla.", I'm aware, I'm not to the point of adding checks in for that yet.