Sunday, July 24, 2011

ADD REPLY FUNCTIONALITY TO OUR COMMENT SYSTEM part2

this page post.php
<?php include_once "mysql.php";
if ($_POST['wall'] == "post"){
$name = $_POST['name1'];//name1 is parameter from the jquery function 
$comment = $_POST['comment1'];//comment1 is parameter from the jquery function  
if ($comment=="" || $name==""){exit();}// if no name or comment exit the script
else{
//insert the name and comment into database 
$sql = mysql_query("INSERT INTO comment (name,comment) VALUES('$name','$comment')")
or die (mysql_error()); 
$id = mysql_insert_id();//the auto incremented id of the commet.
it important to this line  
// the inserted comment will renderd by the "$("#result").prepend(data).show();" from jquery
echo 'name : '.$name.'<br />comment : '.$comment.'<br />
<div id="'.$id.'" class="reply"><span>reply</span><hr>name<br />
<input type="text" id="repname'.$id.'" />
<br />
comment<br />
<textarea id="repcomment'.$id.'" cols="30" rows="2"></textarea>
<br />
<input type="submit" name="button" id="button" value="Submit" 
onclick="return false" onmousedown="javascript:reply('.$id.');"/></form>

<br />' . $r . '</div> <hr>';
} } else if ($_POST['wall'] == "reply"){
$repto = $_POST['repto1'];//repto1 is parameter from the jquery function  
$repname = $_POST['repname1'];//repname1 is parameter from the jquery function  
$repcomment = $_POST['repcomment1'];//repcomment1 is parameter from the jquery function  

if ($repcomment=="" || $repname==""){exit();}// if no $repname or $repcomment exit the script
else{
//insert the values above into database 
$sql = mysql_query("INSERT INTO reply (repto,repname,repcom) VALUES($repto,'$repname','$repcomment')")
or die (mysql_error());  
// the inserted reply will renderd by the "$("#"+ comid).append(data);" from jquery
echo 'name : '.$repname.'<br />comment : '.$repcomment.'<hr>';
}
} ?>

No comments:

Post a Comment