Hender
King Tinkerer
Im coding a shoutbox for ModernMafia.
Whats wrong with my form?
My result:
Shoutbox code.
Shoutboxpost.php
Yes, im probably being lazy but, who cares. Roast me.
Whats wrong with my form?
My result:
You must be registered for see links
Shoutbox code.
PHP:
<script>
$(document).on('keypress', '#message', function(event) {
//var keycode = (event.keyCode ? event.keyCode : event.which);
if(event.keyCode == 13) {
event.preventDefault();
console.log("enter click");
//script
var message = $("#message").val();
// Returns successful data submission message when the entered information is stored in database.
var dataString = 'message='+ message;
// AJAX Code To Submit Form.
$.ajax({
type: "POST",
url: "shoutboxpost.php",
data: dataString,
cache: false,
success: function(result){
console.log("worked");
//console.log(result);
}
});
}
});
</script>
<form role="form" id="message">
<input name="message" placeholder="Enter your message" type="text" class="textarea" style="width: 100%;margin-bottom: -3px;">
</form>
Shoutboxpost.php
PHP:
<?php
include "configisheredontworryabouthefilenameok"; //Connects to the DB.
$username= mysql_real_escape_string($_SESSION["real_name"]); // gets the players name from session.
$comment = mysql_real_escape_string($_POST['message']); // Gets the message posted.
$time = gmdate('Y-m-d H:i:s'); // Date & Time format.
$realip= $_SERVER['REMOTE_ADDR']; // gets IP address.
mysql_query("INSERT INTO `chat` ( `id` , `username` , `message`, `time`, `ip` ) VALUES ( '', '$username', '$comment', '$time', `$realip`)"); // enters into chat table.
?>
Yes, im probably being lazy but, who cares. Roast me.