thesmart1
05-13-2007, 05:43 PM
I'm trying to add a comments system to a page on my site. Users will add a comment using a form and submit it using AJAX. I already have a ratings system that works in a similar way. I can't seem to get the add comment form to work, though. It just tries to load the current url with the specified variables attached. Could the two AJAX items be conflicting?
The page:
<?php include("headtags.php"); ?>
<title>Red Hat Entertainment - Playing - <?php echo $_GET["movie"]; ?></title>
<link rel="stylesheet" type="text/css" href="play.css" />
<script type="text/javascript"><!--
var xmlHttp
function addrating(str){
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null){
alert("Your browser doesn't support the technology required for this function.")
return
}
var url="add_user_rating.php"
url=url+"?movie=<?php echo $_GET['movie']; ?>&rating="+str
url=url+"&sid="+Math.random()
//xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function GetXmlHttpObject(){
var xmlHttp=null;
try{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e){
//Internet Explorer
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
--></script>
<script type="text/javascript"><!--
var xmlHttp
function addcomment(name,comment){
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null){
alert("Your browser doesn't support the technology required for this function.")
return
}
var url="add_comment.php"
url=url+"?movie=<?php echo $_GET['movie']; ?>&name="+name+"&comment="+comment
comurl=comurl+"&sid="+Math.random()
//xmlHttp.onreadystatechange=stateChanged
xmlHttpcom.open("GET",url,true)
xmlHttpcom.send(null)
}
function GetXmlHttpObject(){
var xmlHttp=null;
try{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e){
//Internet Explorer
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
--></script>
</head>
<body>
<div class="header">
<?php include("header.php"); ?>
</div>
<div class="navbar">
<?php include("nav.php"); ?>
</div>
<div class="main">
<div>
<?php
if ($_GET["movie"]==null || $_GET["quality"]==null){
echo "No movie and/or quality was specified.";
}
else {
echo '<embed name="MediaPlayer" type="application/x-mplayer2" autostart="1" loop="false" displaysize="4" pluginspage="http://www.microsoft.com/windows/mediaplayer/en/download/" ShowTracker="1" ShowControls="1" ShowStatusBar="0" EnableContextMenu="0" src="movies/'.$_GET["movie"].'/'.$_GET["movie"].'_'.$_GET["quality"].'.wmv" class="player">';
}
?>
<div class="info">
<h2><?php echo $_GET['movie']; ?></h2>
<p>
<br />
<?php
if ($_GET["movie"]!=null && $_GET["quality"]!=null){
include('disp_user_rating.php');
$aurwidth=$aur*25;
if ($aur!=0){
$aurating=$aur.'/5.0 stars';
}
else {
$aurating='Not Yet Rated';
}
echo 'Average User Rating: <div class="aur" style="position:relative;left:20px;width:125px;height:23px;z-index:4;overflow:hidden;"><div><img src="stars.gif" alt="'.$aurating.'" title="'.$aurating.'" style="position:relative;z-index:3;" /><div style="position:relative;left:0px;top:-30px;background-color:#ffcc00;height:34px;width:'.$aurwidth.'px;z-index:2;"></div></div></div><br />';
}
?>
<form>
<select name="ratingselect" onchange="addrating(this.value)">
<option value="null" selected="selected">Rate this movie</option>
<option value="1">1 (Worst)</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5 (Best)</option>
</select>
</form>
</div>
</div>
<div class="comments">
<table>
<tr><td><h3>Comments</h3></td></tr><?php
$commentdblink=mysql_connect('h50mysql11.secureserver.net','rhe_data','*****')
or die('Failed to log your view. Please notify webmaster at <a href="mailto:rhe@pehjota.com">rhe@pehjota.com</a> and include the code "comhostcon".');
mysql_select_db('rhe_data')
or die('Failed to log your view. Please notify webmaster at <a href="mailto:rhe@pehjota.com">rhe@pehjota.com</a> and include the code "comdbsel".');
$commentresult=mysql_query('SELECT * FROM comments WHERE movie="'.$_GET['movie'].'"')
or die('Failed to load views. Please notify webmaster at <a href="mailto:rhe@pehjota.com">rhe@pehjota.com</a> and include the code "comquerysel".');
while ($row = mysql_fetch_array($commentresult)){
$datetime=$row['datetime'];
$name=$row['name'];
$comment=$row['comment'];
$commentid=$row['id'];
echo "\n\t\t\t\t\t";
echo '<tr><td> </td></tr>';
echo "\n\t\t\t\t\t";
echo '<tr><td><table class="comment"><tr><td class="comname">'.$name.'</td><td class="comdt">'.$datetime.'</td>';
if (isset($_COOKIE['rhe_block_visit_logging'])){
echo '<td class="comdel">Del ('.$commentid.')</td>';
}
echo '</tr>';
echo '<tr><td colspan="';
if (isset($_COOKIE['rhe_block_visit_logging'])){
echo '3';
}
else {
echo '2';
}
echo '" class="comcom">'.$comment.'</td></tr></td></tr></table>';
}
echo "\n";
mysql_free_result($commentresult);
mysql_close($commentdblink);
?>
</table>
<form>
Name: <input type="text" name="name" />
Comment: <textarea name="comment"></textarea>
<input type="submit" onclick="addcomment(name.value,comment.value)" />
</form>
</div>
</div>
</body>
</html>
<?php include("/home/content/p/e/h/pehjota/html/globalfooter.php"); ?>
The page:
<?php include("headtags.php"); ?>
<title>Red Hat Entertainment - Playing - <?php echo $_GET["movie"]; ?></title>
<link rel="stylesheet" type="text/css" href="play.css" />
<script type="text/javascript"><!--
var xmlHttp
function addrating(str){
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null){
alert("Your browser doesn't support the technology required for this function.")
return
}
var url="add_user_rating.php"
url=url+"?movie=<?php echo $_GET['movie']; ?>&rating="+str
url=url+"&sid="+Math.random()
//xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function GetXmlHttpObject(){
var xmlHttp=null;
try{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e){
//Internet Explorer
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
--></script>
<script type="text/javascript"><!--
var xmlHttp
function addcomment(name,comment){
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null){
alert("Your browser doesn't support the technology required for this function.")
return
}
var url="add_comment.php"
url=url+"?movie=<?php echo $_GET['movie']; ?>&name="+name+"&comment="+comment
comurl=comurl+"&sid="+Math.random()
//xmlHttp.onreadystatechange=stateChanged
xmlHttpcom.open("GET",url,true)
xmlHttpcom.send(null)
}
function GetXmlHttpObject(){
var xmlHttp=null;
try{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e){
//Internet Explorer
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
--></script>
</head>
<body>
<div class="header">
<?php include("header.php"); ?>
</div>
<div class="navbar">
<?php include("nav.php"); ?>
</div>
<div class="main">
<div>
<?php
if ($_GET["movie"]==null || $_GET["quality"]==null){
echo "No movie and/or quality was specified.";
}
else {
echo '<embed name="MediaPlayer" type="application/x-mplayer2" autostart="1" loop="false" displaysize="4" pluginspage="http://www.microsoft.com/windows/mediaplayer/en/download/" ShowTracker="1" ShowControls="1" ShowStatusBar="0" EnableContextMenu="0" src="movies/'.$_GET["movie"].'/'.$_GET["movie"].'_'.$_GET["quality"].'.wmv" class="player">';
}
?>
<div class="info">
<h2><?php echo $_GET['movie']; ?></h2>
<p>
<br />
<?php
if ($_GET["movie"]!=null && $_GET["quality"]!=null){
include('disp_user_rating.php');
$aurwidth=$aur*25;
if ($aur!=0){
$aurating=$aur.'/5.0 stars';
}
else {
$aurating='Not Yet Rated';
}
echo 'Average User Rating: <div class="aur" style="position:relative;left:20px;width:125px;height:23px;z-index:4;overflow:hidden;"><div><img src="stars.gif" alt="'.$aurating.'" title="'.$aurating.'" style="position:relative;z-index:3;" /><div style="position:relative;left:0px;top:-30px;background-color:#ffcc00;height:34px;width:'.$aurwidth.'px;z-index:2;"></div></div></div><br />';
}
?>
<form>
<select name="ratingselect" onchange="addrating(this.value)">
<option value="null" selected="selected">Rate this movie</option>
<option value="1">1 (Worst)</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5 (Best)</option>
</select>
</form>
</div>
</div>
<div class="comments">
<table>
<tr><td><h3>Comments</h3></td></tr><?php
$commentdblink=mysql_connect('h50mysql11.secureserver.net','rhe_data','*****')
or die('Failed to log your view. Please notify webmaster at <a href="mailto:rhe@pehjota.com">rhe@pehjota.com</a> and include the code "comhostcon".');
mysql_select_db('rhe_data')
or die('Failed to log your view. Please notify webmaster at <a href="mailto:rhe@pehjota.com">rhe@pehjota.com</a> and include the code "comdbsel".');
$commentresult=mysql_query('SELECT * FROM comments WHERE movie="'.$_GET['movie'].'"')
or die('Failed to load views. Please notify webmaster at <a href="mailto:rhe@pehjota.com">rhe@pehjota.com</a> and include the code "comquerysel".');
while ($row = mysql_fetch_array($commentresult)){
$datetime=$row['datetime'];
$name=$row['name'];
$comment=$row['comment'];
$commentid=$row['id'];
echo "\n\t\t\t\t\t";
echo '<tr><td> </td></tr>';
echo "\n\t\t\t\t\t";
echo '<tr><td><table class="comment"><tr><td class="comname">'.$name.'</td><td class="comdt">'.$datetime.'</td>';
if (isset($_COOKIE['rhe_block_visit_logging'])){
echo '<td class="comdel">Del ('.$commentid.')</td>';
}
echo '</tr>';
echo '<tr><td colspan="';
if (isset($_COOKIE['rhe_block_visit_logging'])){
echo '3';
}
else {
echo '2';
}
echo '" class="comcom">'.$comment.'</td></tr></td></tr></table>';
}
echo "\n";
mysql_free_result($commentresult);
mysql_close($commentdblink);
?>
</table>
<form>
Name: <input type="text" name="name" />
Comment: <textarea name="comment"></textarea>
<input type="submit" onclick="addcomment(name.value,comment.value)" />
</form>
</div>
</div>
</body>
</html>
<?php include("/home/content/p/e/h/pehjota/html/globalfooter.php"); ?>