I'm trying to update my mysql table with the name of the winner in a simple raffle. the raffle works great, but I have been unable to get the name of the winner to update once is picked.
index.php
<?php include_once('connect.php'); //connect db ?>
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Raffle drawing</title>
<meta name="Author" content="Kyle Banerjee" />
<meta name="keywords" content="raffle drawing prizes" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<link title="new" rel="stylesheet" href="includes/default.css" TYPE="text/css" />
<script language='javascript' src="includes/raffle.js"></script>
</head>
<body>
<center>
<div><h1>And the winner is</h1></div>
</center>
<p />
<center>
<table><tr><td>
<div id='results'>
</div>
</td></tr></table>
<div id="show">
<a class="blue" onClick="hideNames(); return false;">Hide names in box</a>
</div>
<p /> <p />
</center>
</h1>
<center><form name="f" onSubmit="processForm(document.f); return false;">
<input type="submit" value="Find the Winner!"><p />
<div id="names">
<textarea name="userinput" style="display:none" rows="50" cols="50">
<?php
$query = "select * from member where status=0";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)){
echo $row['name'] . "\n" ;
}
?>
</textarea>
</div>
</form></center>
</body>
</html>
JS
var milisec=0;
var seconds=0;
var minutes=0;
var winner = '';
var contestants=[];
function processForm(obj_f) {
seconds = 70;
contestants = obj_f.userinput.value.split("\n");
findWinner();
}
function winnerIs() {
document.getElementById('results').innerHTML='<p /><winner>' + contestants[Math.floor(Math.random()*contestants.length)] + '</winner>';
//savedata();
}
function findWinner(){
var x=0;
if (milisec<=0){
milisec=9
seconds-=1
}
if (seconds<=-1){
milisec=0
}
if(seconds <= 0){
clearTimeout();
// keep trying if a black line is retrieved. Give up after 100 tries;
winner = contestants[Math.floor(Math.random()*contestants.length)];
while (winner.length < 2) {
winner = contestants[Math.floor(Math.random()*contestants.length)];
x++;
if (x > 100) {break;}
}
document.getElementById('results').innerHTML='<div id="final"><winner>' + winner + '!</winner></div>';
} else {
winnerIs();
setTimeout("findWinner()",10)
milisec-=1
}
}
function hideNames() {
document.getElementById('names').style.visibility='hidden';
document.getElementById('show').innerHTML='<a class="blue" onClick="showNames(); return false;">Show names in box</a>';
}
function showNames() {
document.getElementById('names').style.visibility='visible';
document.getElementById('show').innerHTML='<a class="blue" onClick="hideNames(); return false;">Hide names in box</a>';
}
function savedata() {
}
any ideas on how I can get it to update to db set status=1 where name = winner??
Related
I made a chat service in php. When you get to the chat, it says "Welcome, --Username--." My problem is I added a login field, now I can't send messages and the username isn't displayed. I've looked everywhere but it seems since my code is so "unique", nothing seems to be helping. --i didn't make this all on my own, I used someone else's code for the login and someone's code for the service itself.
login.php
<?php
session_start();
echo isset($_SESSION['login']);
if(isset($_SESSION['login'])) {
header('LOCATION:admin.php'); die();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='content-type' content='text/html;charset=utf-8' />
<title>Login</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<h3 class="text-center">Login</h3>
<?php
if(isset($_POST['submit'])){
$username = $_POST['username']; $password = $_POST['password'];
if($username === 'admin' && $password === 'password'){
$_SESSION['login'] = true; header('LOCATION:admin.php'); die();
} {
echo "<div class='alert alert-danger'>Username and Password do not match.</div>";
}
if($username === 'admon' && $password === 'password'){
$_SESSION['login'] = true; header('LOCATION:admin.php'); die();
} {
echo "<div class='alert alert-danger'>Username and Password do not match.</div>";
}
}
?>
<form action="" method="post">
<div class="form-group">
<label for="username">Username:</label>
<input type="text" class="form-control" id="username" name="username" required>
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd" name="password" required>
</div>
<button type="submit" name="submit" class="btn btn-default">Login</button>
</form>
</div>
</body>
</html>
admin.php
<?php
session_start();
if(!isset($_SESSION['login'])) {
header('LOCATION:login.php'); die();
}
if(isset($_GET['logout'])){
//Simple exit message
$logout_message = "<div class='msgln'><span class='left-info'>User <b class='user-name-left'>". $_SESSION['name'] ."</b> has left the chat session.</span><br></div>";
file_put_contents("log.html", $logout_message, FILE_APPEND | LOCK_EX);
session_destroy();
header("Location: login.php"); //Redirect the user
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>English Pricks</title>
<meta name="description" content="A Group Chat." />
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div id="wrapper">
<div id="menu">
<p class="welcome">Welcome, <b><?php echo $username['username']; ?></b>. Image Dump...</p>
<p>Emoji's → </p>
<button id="emoji-button" style="border: none;">😀</button>
<p class="logout"><a id="exit" href="#">Leave</a></p>
</div>
<div id="chatbox">
<?php
if(file_exists("log.html") && filesize("log.html") > 0){
$contents = file_get_contents("log.html");
echo $contents;
}
?>
</div>
<form name="message" action="">
<input name="usermsg" type="text" id="usermsg" style="outline: none;" spellcheck="true"/>
<input name="submitmsg" type="submit" id="submitmsg" value="↑" />
</form>
</div>
<script type="text/javascript" src="./jquery.min.js"></script>
<script src="emoji.js"></script>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function () {
var picker = new EmojiButton();
var button = document.querySelector('#emoji-button');
button.addEventListener('click', function () {
picker.showPicker(button);
picker.on('emoji', emoji => {
document.querySelector('#usermsg').value += emoji;
});
});
});
</script>
<script type="text/javascript">
$(document).ready(function () {
$("#submitmsg").click(function(){
var clientmsg = $.trim($("#usermsg").val());
if(clientmsg.length >= 1){ // Prevents Spamming the Enter Key
$.post("post.php", {text: clientmsg});
$("#usermsg").val("");
}else{
}
return false;
});
function loadLog() {
var oldscrollHeight = $("#chatbox")[0].scrollHeight - 20; //Scroll height before the request
$.ajax({
url: "log.html",
cache: false,
success: function (html) {
$("#chatbox").html(html); //Insert chat log into the #chatbox div
//Auto-scroll
var newscrollHeight = $("#chatbox")[0].scrollHeight - 20; //Scroll height after the request
if(newscrollHeight > oldscrollHeight){
$("#chatbox").animate({ scrollTop: newscrollHeight }, 'normal'); //Autoscroll to bottom of div
}
}
});
}
setInterval (loadLog, 1000);
$("#exit").click(function () {
var exit = confirm("Are you sure you want to leave?");
if (exit == true) {
window.location = "index.php?logout=true";
}
});
});
</script>
</body>
</html>
In login.php file else was missing in if blocks and in order to see username you should add it to $_SESSION in the same way as you did with
$_SESSION['login'], cause i don't see anything else which can serve as temp storage in provided code. Another issue is that you placed header() function with login and password check right inside html code. This will trigger warning on a runtime that headers were already sent. In order to avoid that place your checking code in the top of the file and also check if there are no spaces before or after <?php php opening tag.
Example of fixed login.php file you can find below.
<?php
session_start();
function setSessionData($name, $value) {
$_SESSION[$name] = $value;
}
function redirectWithData($username = '') {
setSessionData('login', true);
setSessionData('username', $username);
header('Location:admin.php');
die();
}
if(isset($_SESSION['login'])) {
header('Location:admin.php'); die();
}
if(isset($_POST['submit'])) {
$username = $_POST['username']; $password = $_POST['password'];
if($username === 'admin' && $password === 'password'){
redirectWithData($username);
} elseif($username === 'admon' && $password === 'password'){
redirectWithData($username);
} else {
echo "<div class='alert alert-danger'>Username and Password do not match.</div>";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='content-type' content='text/html;charset=utf-8' />
<title>Login</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<h3 class="text-center">Login</h3>
<form action="" method="post">
<div class="form-group">
<label for="username">Username:</label>
<input type="text" class="form-control" id="username" name="username" required>
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd" name="password" required>
</div>
<button type="submit" name="submit" class="btn btn-default">Login</button>
</form>
</div>
</body>
</html>
On admin page you can then display username
Welcome, <b><?php echo $_SESSION['username']; ?>
Regarding admin.php functionality. Logic for adding messages according to JavaScript code located in post.php file.
$.post("post.php", {text: clientmsg});
So, why its adding or not adding it is hard to answer for obvious reasons )
And btw, in your logout logic in admin.php file change
window.location = "index.php?logout=true"; -> window.location = "?logout=true"; it will fallback to the same page on which you already have redirect logic.
I'm currently working on a website (a quiz), but have run into a somewhat strange issue where my php code is not displaying after a certain point. I'll also note that while I am a student, this is for a research project that I was given express permission from my advisor to post about.
http://zephyr.sista.arizona.edu/learn2cal/index
The issue itself is on the /quiz.php page, but that will give you server errors if you try to access it without going through the start page first.
My own code looks something like this:
<?php
require_once("./databaseAdaptor.php");
$page = '0';
if(isset($_POST["page"])) {
$page = $_POST["page"];
} else {
echo "";
$page = '1';
}
if(isset($_POST['user'])) {
$user = $_POST['user'];
} else {
echo "error";
}
echo $user;
echo $page;
?>
<!DOCTYPE HTML5>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<title>FOOD CALORIES</title>
<link rel="stylesheet" href="css/styles.css"/>
</head>
<body>
<div>
<h4>Calorie4Food</h4>
</div>
<article>
<center>
<h5>How many calories are in the food pictured here? </h5>
<h6>(Type a number in the box)</h6>
<!-- progress bar -->
<num>Progress Bar</num>
<label2><progress id="pro" value="<?=($page-1)*(10/3) ?>" max="100"></progress></label2>
<num id="num"><?=floor(($page-1) * (10/3)) ?></num> <num>%</num>
<br><br>
<?php
require_once("/databaseAdaptor.php");
$image = $myDatabaseFunctions->getImage(1)[0];
$imageIDArray = explode("/", $image);
$imageID = $imageIDArray[1];
?>
<img src="./<?=$image?>.jpg" alt=""/>
<section>
<form method="post" action="./reinforce.php" onsubmit="checkform()">
<input type="number" name="estimate" value="quizInput"/>
<word>cal</word>
<input type='hidden' name='start' value='<?=date('Y-m-d G:i:s')?>'>
<input type='hidden' name='imageID' value='<?=$imageID?>'>
<input type="hidden" name="page" value="<?=($page+1)?>"/>
<input type='hidden' name='user' value='<?=$user?>'>
<input id="submit" type="submit" class="button-next" value="Next" id="btn1"/>
</form>
</section>
<script type="text/javascript">
function checkform(){
if(document.getElementById('q1').value==""){
alert('Please input a number!');
document.getElementById('q1').focus();
return false;
}
}
var progressBar = document.getElementById('pro');
function updateProgress(newValue) {
progressBar.value = newValue;
document.getElementById('num').textContent=newValue;
}
</script>
<br></br>
</center>
</article>
</body>
</html>
When I attempt to load the question page, everything about the page is displaying correctly until you pass the progress bar. After that, the live page looks like this:
<!DOCTYPE HTML5>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<title>FOOD CALORIES</title>
<link rel="stylesheet" href="css/style.css"/>
</head>
<body>
<div>
<h4>Calorie4Food</h4>
</div>
<article>
<center>
<h5>How many calories are in the food pictured here? </h5>
<h6>(Type a number in the box)</h6>
<!-- progress bar -->
<num>Progress Bar</num>
<label2><progress id="pro" value="0" max="100"></progress></label2>
<num id="num">0</num> <num>%</num>
<br><br>
I'm not sure why this is be happening or where I should begin attempting to debug this problem, any advice would be greatly appreciated!
Update: /databaseAdaptor.php is there and running correctly as far as the rest of the pages are concerned. Thanks so much for catching the second require! Can't believe I missed that.
I am working on a small project. I have created a PHP page in that as soon as a button in clicked a function named sendMessage should get executed but instead it is showing me uncaught reference error.
My error:
Uncaught ReferenceError:sendMessage is not defined at HTMLInputElement.onclick
line 29. At last onclick call
Here is my js file named chat.js:
function btn() {
var s = document.getElementById("chat_id");
var o = s.options[s.selectedIndex].value;
var x = document.getElementsByClassName("chat");
x[0].style.display = "inline-block";
x[1].innerHTML = "<span>" + "Chatting with:" + o + "<span>";
}
function sendMessage() {
var msg = document.getElementById("msg").value;
if (msg.length === 0 || msg === "") {
alert("please enter some message");
return;
}
var sender = document.getElementById("username").value;
var sendto = document.getElementById("chat_id").options[document.getElementById("chat_id").selectedIndex].value;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 400) {
document.getElementById("chat_logs").innerHTML = xhttp.responseText;
}
xhttp.open('GET', 'send_messages.php?sender=' + sender + 'sendto=' + sendto + 'message=' + msg, true);
xhttp.send();
}
}
function test() {
alert("lol");
}
My PHP code:
<?php
include ('db.php');
session_start();
if(empty($_SESSION['user_logs'])){ //check if user session is set
header('Location:login.php'); //redirect to login page if user session is not set
}
?>
<!DOCTYPE html>
<html>
<head>
<title>chat box</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script type="text/javascript" src="chat.js"></script>
<link rel="stylesheet" href="chatbox.css" />
</head>
<body>
<div class="container cont">
<p>
Logout <?php echo $_SESSION['user_logs']; ?>
</p>
<input type="hidden" id="username" value=<?php echo $_SESSION[ 'user_logs']; ?>>
<p>
<label for="chatwith">Chat with:</label>
<select name="chat_user" id="chat_id" class="selectpicker">
<option disabled selected>select</option>
<?php
$current_user=$_SESSION['user_logs'];
$rows=mysqli_query($con,"select username from users where username!='".$current_user."'");
while($rowsArray=mysqli_fetch_array($rows)):
?>
<option value=<?php echo $rowsArray[ 'username']; ?>>
<?php echo $rowsArray['username']; ?>
</option>
<?php endwhile;?>
</select>
<input type="button" id="btn_chat" name="toggle" value="chat" class="btn btn-info" onclick="btn();" />
<div id="chat_div" class="chat">
<span class="chat">Chatting with:</span>
<div class="chat" id="chat_logs"></div>
<div class="chat" id="input">
<textarea value="" placeholder="Enter message" id="msg" name="message" required maxlength="150"></textarea>
<input type="button" id="btn-send" class="btn btn-primary" value="send" onclick="sendMessage();" />
</div>
</div>
</div>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
window.onload = function hide_input_items()
{
var inputs=document.getElementsByTagName('input');
for(var i=0;i<inputs.length;i++)
{
if(inputs[i].type=='text')
{
inputs[i].disabled=1;
}
}
var updates = document.getElementById('update');
var cancels = document.getElementById('cancel');
for(var j=1;j<up;j++)
{
updates[j].style.visibility = "hidden";
cancels[j].style.visibility = "hidden";
}
}
</script>
</head>
<body>
<?php
$counter=0;
for($i=1;$i<10;$i++)
{
$counter++;
$name= "name".$counter;
$update="update".$counter;
$cancel="cancel".$counter;
$edit= "edit".$counter;
?>
<input type="text" name="name" id="name" id="<?php echo $name;?>" value="hi" />
<input type="button" name="edit" id="name" id="<?php echo $edit;?>" value="Edit" onclick="focuse('<?php //echo $id.",".$update.",".$cancel.",".$edit;?>')"/>
<input type="button" name="update" id="name" id="<?php echo $update;?>" value="Update" onclick="display('<?php //echo $cancel;?>');"/>
<input type="button" name="cancel" id="name" id="<?php echo $cancel;?>" value="Cancel" onclick="show()"/>
<br />
<?php
}?>
<input type="button" name="button" onclick="hide_all();" value="Hide all" />
</body>
</html>
I want to hide update and cancel button on page load but it does not working when i add second loop in page load function then then upper loop is also disable.Here above is my complete code please do give some suggestion if do you have. Thanks.
I'm trying to do a comment form, that puts the comment in my mysql database, and puts the new comment on my page right after submitting (and clears the form). But somehow you have to always refresh to see the new comments and if you click on submit more than once it shows duplicated comments after refresh. How can I solve that problem? I'm kinda a noob, so my codes are mostly from tutorials that I don't fully understand yet...
my php-page:
<?php
// Error reporting:
error_reporting(E_ALL^E_NOTICE);
include "connect.php";
include "comment.class.php";
$comments = array();
$result = mysql_query("SELECT * FROM comments ORDER BY id ASC");
while($row = mysql_fetch_assoc($result))
{
$comments[] = new Comment($row);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Bausatz</title>
<meta name="" content="">
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/main.css">
<script src="js/modernizr-2.7.1.min.js"></script>
<style type="text/css"></style>
<link href='http://fonts.googleapis.com/css?family=Montserrat:400' rel='stylesheet'
type='text/css'>
</head>
<body>
<header>
<div class="logo">
<span class="col">ON THE </span>W<span class="col">OODWAY</span>
</div>
<nav>
TRAVELS
BLOG
ME
</nav>
</header>
<div class="main">
<div class="contentwrapper">
<div class="entry">
</div>
<div class="comment">
<div id="each">
<?php
foreach($comments as $c){
echo $c->markup();
}
?>
</div>
<div id="addCommentContainer">
<p>Add a Comment</p>
<form id="addCommentForm" method="post" action="">
<div>
<label for="name">Your Name</label>
<input type="text" name="name" id="name" />
<label for="email">Your Email</label>
<input type="text" name="email" id="email" />
<label for="body">Comment Body</label>
<textarea name="body" id="body" cols="20" rows="5"></textarea>
<input type="submit" id="submit" value="Submit" >
</div>
</form>
</div>
</div>
</div>
</div>
<div class="unten">
<nav>
contact
copyright
</nav>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/jquery-1.9.1.min.js">
<\/script>')</script>
<script type="text/javascript" src="js/comment.js"></script>
</body>
</html>
jQuery:
$(document).ready(function(){
var working = false;
$('#addCommentForm').submit(function(e){
e.preventDefault();
if(working) return false;
working = true;
$('#submit').val('Working..');
$('span.error').remove();
/* Sending the form fileds to submit.php: */
$.post('submit.php',$(this).serialize(),function(msg){
working = false;
$('#submit').val('Submit');
if(msg.status){
$(msg.html).hide().insertBefore('#addCommentContainer').slideDown();
$('#body').val('');
}
else {
$.each(msg.errors,function(k,v){
$('label[for='+k+']').append('<span class="error">'+v+'</span>');
});
}
},'json');
});
});
comment.class.php
<?php
class Comment
{
private $data = array();
public function __construct($row)
{
/*
/ The constructor
*/
$this->data = $row;
}
public function markup()
{
/*
/ This method outputs the XHTML markup of the comment
*/
// Setting up an alias, so we don't have to write $this->data every time:
$d = &$this->data;
$link_open = '';
$link_close = '';
// Converting the time to a UNIX timestamp:
$d['dt'] = strtotime($d['dt']);
return '
<div class="comment">
<div class="name">'.$link_open.$d['name'].$link_close.'</div>
<div class="date" title="Added at '.date('H:i \o\n d M
Y',$d['dt']).'">'.date('d M Y',$d['dt']).'</div>
<p>'.$d['body'].'</p>
</div>
';
}
public static function validate(&$arr)
{
/*
/ This method is used to validate the data sent via AJAX.
/
/ It return true/false depending on whether the data is valid, and populates
/ the $arr array passed as a paremter (notice the ampersand above) with
/ either the valid input data, or the error messages.
*/
$errors = array();
$data = array();
// Using the filter_input function introduced in PHP 5.2.0
if(!($data['email'] = filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL)))
{
$email = '';
}
// Using the filter with a custom callback function:
if(!($data['body'] =
filter_input(INPUT_POST,'body',FILTER_CALLBACK,array('options'=>'Comment::validate_text'))) )
{
$errors['body'] = 'Please enter a comment body.';
}
if(!($data['name'] = filter_input(INPUT_POST,'name',FILTER_CALLBACK,array('options'=>'Comment::validate_text'))))
{
$errors['name'] = 'Please enter a name.';
}
if(!empty($errors)){
// If there are errors, copy the $errors array to $arr:
$arr = $errors;
return false;
}
foreach($data as $k=>$v){
$arr[$k] = mysql_real_escape_string($v);
}
$arr['email'] = strtolower(trim($arr['email']));
return true;
}
private static function validate_text($str)
{
if(mb_strlen($str,'utf8')<1)
return false;
$str = nl2br(htmlspecialchars($str));
$str = str_replace(array(chr(10),chr(13)),'',$str);
return $str;
}
}
?>
submit.php
<?php
error_reporting(E_ALL^E_NOTICE);
include "connect.php";
include "comment.class.php";
$arr = array();
$validates = Comment::validate($arr);
if($validates)
{
mysql_query(" INSERT INTO comments(name,url,email,body)
VALUES (
'".$arr['name']."',
'".$arr['url']."',
'".$arr['email']."',
'".$arr['body']."'
)");
$arr['dt'] = date('r',time());
$arr['id'] = mysql_insert_id();
$arr = array_map('stripslashes',$arr);
$insertedComment = new Comment($arr);
echo json_encode(array('status'=>1,'html'=>$insertedComment->markup()));
}
else
{
echo '{"status":0,"errors":'.json_encode($arr).'}';
}
?>
connect.php
<?php
$db_host = '*****';
$db_user = '*****';
$db_pass = '*****';
$db_database = '*****';
$link = #mysql_connect($db_host,$db_user,$db_pass) or die('Unable to establish a DB connection');
mysql_query("SET NAMES 'utf8'");
mysql_select_db($db_database,$link);
?>
Why don't you try appending it to the rest of the comments?
Change this:
$(msg.html).hide().insertBefore('#addCommentContainer').slideDown();
To this:
$(msg.html).hide().appendTo('#each').slideDown();