Post: [PHP] [JS] [jQuery] Code not inserting
12-06-2015, 07:42 AM #1
Dan
I'm a god.
(adsbygoogle = window.adsbygoogle || []).push({}); Code doesn't seem to insert into the DB

sendshout.php
    
$message = $_POST['message'];
$date = new DateTime();
$date2 = $date->format('l h:i A"'Winky Winky;
$user = $username;

$DB_con->prepare("INSERT INTO shouts (date, username, shout) VALUES Upside Down Happydate, :username, :shout)");
$DB_con->execute(array(':date' => $date2, ':username' => $user, ':shout' => $message));


JS/jQuery
    
function sendShout()
{
var message = $(".input_custom").value;
var send = new XMLHttpRequest();
send.open("POST", "sendshout.php", true);
send.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
send.send("?message="+message);
$(".input_custom").value='';
return false;
}


index.php
    
<form onsubmit="return sendShout();" class="form-inline">
<div class="form-group ">
<input type="text" class="input_custom" style="color:black;" id="Message"> <button type="submit" class="btn btn-default">Send</button>
</div>
</form>


Need any other information, quote me or send me a PM, thanks for any help.
12-07-2015, 01:36 PM #2
JB
[i]Remember, no Russian.[/i]
    $DB_con->execute(array(':date' => $date2, ':username' => $user, ':shout' => $message));


Var_dump that line
12-08-2015, 06:43 AM #3
Dan
I'm a god.
Originally posted by JB View Post
    $DB_con->execute(array(':date' => $date2, ':username' => $user, ':shout' => $message));


Var_dump that line


Instead of using XMLHttpRequest, I used the AJAX post:

    
function sendShout()
{
var message = $("#Message").val();
var username = $("#username").html();
$.ajax({
type: 'POST',
url: 'sendshout.php',
data:
{
message: message,
username: username
},
success: function(response) {
content.html(response);
update();
}
});
update();
}


Now the problem is I can't get this div to refresh.

AJAX:
    
function update()
{
setInterval(function() {
$.get("getshouts.php", function (result) {
$('#shoutbox'Winky Winky.html(result);
});
}, 10000);
}


HTML:
    
<div class="shouts" id="shoutbox">
</div>
12-08-2015, 06:14 PM #4
JB
[i]Remember, no Russian.[/i]
Originally posted by Dan View Post
Instead of using XMLHttpRequest, I used the AJAX post:

    
function sendShout()
{
var message = $("#Message").val();
var username = $("#username").html();
$.ajax({
type: 'POST',
url: 'sendshout.php',
data:
{
message: message,
username: username
},
success: function(response) {
content.html(response);
update();
}
});
update();
}


Now the problem is I can't get this div to refresh.

AJAX:
    
function update()
{
setInterval(function() {
$.get("getshouts.php", function (result) {
$('#shoutbox'Winky Winky.html(result);
});
}, 10000);
}


HTML:
    
<div class="shouts" id="shoutbox">
</div>


Can you put your source up on github and link me?
12-08-2015, 07:09 PM #5
Dan
I'm a god.
Originally posted by JB View Post
Can you put your source up on github and link me?


I had someone help me with this, all is good now, thanks for helping.

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo