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>';
}
} ?>

ADD REPLY FUNCTIONALITY TO OUR COMMENT SYSTEM part1

continuing from http://phpcoderboard.blogspot.com/2011/06/learn-how-to-create-comment-system-with.html
first create a table and call it "reply" with 4 fields rid, repto, 
repname, repcom.
this page index.php
<?php
include_once "mysql.php";
//////render data that is already stored in the data base
$sql_comments = mysql_query("SELECT * FROM comment ORDER BY id DESC");
while($row = mysql_fetch_array($sql_comments)){
$id = $row["id"];
$name = $row["name"];
$comment = $row["comment"];


$sql_hreply = mysql_query("SELECT * FROM reply WHERE repto !='$id'" );
while($row = mysql_fetch_array($sql_hreply)){
$r = "";
}
$sql_reply = mysql_query("SELECT * FROM reply WHERE repto='$id'" );
while($row = mysql_fetch_array($sql_reply)){
$replycom = $row["repcom"];
$replyname = $row["repname"];
$r .= 'name : '.$replyname.'<br />comment : '.$replycom.'<hr>' ;


}  
$commentlist .= '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>';
}
//////////////the highlight is new code added to old script
?>
<script type="text/javascript" src="js/jquery-1.4.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#loading').hide();
$('#notice').hide();
}); function wall(){
$('#loading').show();
var name = $('#name').val();///#name is the input id and will be equal the variable "name"
var comment = $('#comment').val();/////#comment is textarea id and will be equal the variable "comment"
var URL = "post.php"; /////post.php will be equal the variable "URL" $.post(URL,{wall:"post",name1:name,comment1:comment},function(data){
//parameter wall will be equal "post", name1 will be equal to the var "name" and comment1 will be equal to the var "comment"
$("#result").prepend(data);//.show() the result will be placed above the the #result div
$('#loading').hide();
var name = $('#name').val("");
var comment = $('#comment').val("");
});
} function reply(comid){  
var repname = $('#repname'+comid).val();///#repname is the input id and will be equal the variable "name"
var repcomment = $('#repcomment'+comid).val();/////#repcomment is textarea id and will be equal the variable "comment"
alert(comid + "" + repname + " " + repcomment) var URL = "post.php"; /////post.php will be equal the variable "comment"
$.post(URL,{wall:"reply",repname1:repname,repcomment1:repcomment,repto1:comid},function(data){

//parameter wall will be equal "post", repname1 will be equal to the var "repname" and repcomment1 will be equal to the var "repcomment"
$("#"+ comid).append(data);//render result
//$('#loading').hide();
var repname = $('#repname'+comid).val("");
var repcomment = $('#repcomment'+comid).val("");
});
}  
</script>


<style type="text/css">
<!--
#notice {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: normal;
color: #660000;
background-color: #FFF2F2;
padding: 5px;
border: 1px solid #FF6666;
text-align: center;
}
.reply {
margin-left: 50px;
}
span{
font-size: 14px;
font-weight: bold;
color: #333333;
}
-->
</style>  
<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><form>
name<br />
<input type="text" id="name" />
<br />
comment<br />
<textarea id="comment" cols="45" rows="5"></textarea> <br />
<input type="submit" name="button" id="button" value="Submit" onclick="return false" onmousedown="javascript:wall();"/>
<img src="loading.gif" alt="" width="15" height="15" id="loading" />
<br /></form>
<div id="notice">Your comment will be reviewed by the webmaster before publishing</div>
<div id="result"><?php print"$commentlist";?></div></td>
</tr>



Friday, June 24, 2011

IMPORTANT NOTICE

Hello to everyone, To those who have been following my tutorials. I have create a fan page on facebook so you guys can give a feed backs on my tutorials and say what you like and what you dont like and what kind of tutorials you want more and the kind stuff you want to learn more.
Go to http://www.facebook.com/pages/Phpcoderboard/209608885746800?sk=wall and join.

Thursday, June 23, 2011

TUTORIAL COMMENT SYSTEM WITH ALLOW AND DENY PUBLISHING FUNCTIONALITY

first create table and call it "comment" with 4 fields id, name, comment and status mysql.php  <?php  @mysql_connect("localhost","root","") or die ("could not connect to mysql"); @mysql_select_db("name of your database") or die ("no database"); ?> ///////////page end here
index.php
<?php 
include_once "mysql.php";
//////render data that is already stored in the data base
 $sql_comments = mysql_query("SELECT * FROM comment ORDER BY id DESC");
while($row = mysql_fetch_array($sql_comments)){
$name = $row["name"];
$comment = $row["comment"];
$commentlist .= 'name : '.$name.'<br />comment : '.$comment.'<hr>';
}
//////////////
?>
<script type="text/javascript" src="js/jquery-1.4.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
 $('#loading').hide();
});
function wall(){
$('#loading').show();
  var name = $('#name').val();///#name is the input id from the form and will be equal the variable "name"
  var comment = $('#comment').val();/////#comment is textarea id from the form and will be equal the variable "comment"
  var URL = "post.php"; /////post.php will be equal the variable "comment"
  
  $.post(URL,{wall:"post",name1:name,comment1:comment},function(data){//parameter wall will be equal "post", name1 will be equal to the var "name" and comment1 will be equal to the var "comment"
  if($('#name').val() != "" && $('#comment').val() != ""){//if there is a value for name and comment
  $("#notice").show();//show the div with id = notice
  $("#notice").fadeOut(4000);//fade out the div with id = notice within 4 seconds
  }
  $('#loading').hide();
  var name = $('#name').val("");
  var comment = $('#comment').val("");
  });
 }
</script>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><div id='form'><form>
    name<br />
      <input type="text" id="name" />
      <br />
   comment<br />
      <textarea id="comment" cols="45" rows="5"></textarea>
      <br />
      <input type="submit" name="button" id="button" value="Submit" onclick="return false" onmousedown="javascript:wall();"/><img src="loading.gif" alt="" width="15" height="15" id="loading" />
      <br /></form>
    </div>
      <div id="result"><?php print"$commentlist";?></div></td>
  </tr>
</table>
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 as pending 
  $sql = mysql_query("INSERT INTO comment (name,comment) 
     VALUES('$name','$comment','0')")
     or die (mysql_error());
  }
}
else if ($_POST['wall'] == "allow"){
   $comid = $_POST['cid'];
//set comment from pendded to published
   mysql_query("UPDATE comment SET status='1' WHERE id='$comid'") or die(mysql_error());
   echo"comment has been published.";
   }
   else if ($_POST['wall'] == "deny"){
   $comid = $_POST['cid'];
//delete comment if dennied
   mysql_query("DELETE FROM comment WHERE id='$comid'") or die(mysql_error());
   echo"comment has been deleted.";
   }
?>
admin.php
<?php 
include_once "mysql.php";
//////render data that is already stored in the data base
 $sql_comments = mysql_query("SELECT * FROM comment WHERE status='0' ORDER BY id DESC");
while($row = mysql_fetch_array($sql_comments)){
    $id = $row["id"];
$name = $row["name"];
$comment = $row["comment"];
$commentlist .= '<div id="'.$id.'"><table width="700" border="0" cellspacing="0" cellpadding="0">//we are going to the comment id as div id
  <tr>
    <td width="536" align="left" valign="top">name : '.$name.'<br />comment : '.$comment.'</td>
    <td width="150" align="left" valign="top">
<a id="comment'.$id.'" href="#" onclick="return false" onmousedown="javascript:allow('.$id.');">allow</a>
<a id="comment'.$id.'" href="#" onclick="return false" onmousedown="javascript:deny('.$id.');">deny</a></td>
  </tr>
</table></div><hr>';
}
//////////////
?>
<script type="text/javascript" src="js/jquery-1.4.2.js"></script>
<script type="text/javascript">
  function allow(id){//if admin want to publish
  
  var URL = 'post.php';
  $.post(URL,{wall:"allow",cid:id},function(data){
  $('#'+id).html(data);
  });
  }
  function deny(id){//if admin want to delete
  
  var URL='post.php';
  $.post(URL,{wall:"deny",cid:id},function(data){
  $('#'+id).html(data);
  });
  }
</script>
<style type="text/css">
<!--
.style {
font-size: 16px;
font-weight: bold;
font-family: Arial, Helvetica, sans-serif;
color: #333333;
}
-->
</style>
<span class="style">Pending comments</span>
<hr>
<?php print"$commentlist"; ?>

Monday, June 20, 2011

TUTORIAL:CREATE A LOGIN FORM VALIDATED WITH PHP AND JQUERY

CREATE  TABLE CALLED members WITH 5 FIELDS id firstname lastname email password
INDEX.PHP

<script type="text/javascript" src="js/jquery-1.4.2.js"></script>
<script type="text/javascript">

function login(){
  var email = $('#email').val();//$('#email').val() is the value of the input field with id = email so we are goning to say var email will equal the value of that input
  var pass = $('#pass').val();//$('#pass').val() is the value of the input field with id = pass so we are goning to say var pass will equal the value of that input
  var URL = "parse.php";

  $.post(URL,{action:"login",logname:email,logpass:pass},function(data){
  $("#result").html(data).show();
  });
 }

</script>
<style type="text/css">
<!--
.font {
 font-family: Arial, Helvetica, sans-serif;
 font-size: 12px;
}
.result{
 font-family: Arial, Helvetica, sans-serif;
 font-size: 12px;
 font-weight: bold;
 color: #CC0000;
}
.txtstyle{
 height: 25px;
 width: 200px;
 border-top-width: 2px;
 border-right-width: 1px;
 border-bottom-width: 1px;
 border-left-width: 1px;
 border-top-style: solid;
 border-right-style: solid;
 border-bottom-style: solid;
 border-left-style: solid;
 border-top-color: #DDDDDD;
 border-right-color: #DDDDDD;
 border-bottom-color: #DDDDDD;
 border-left-color: #DDDDDD;
}
.loginbutton {
 clear: left;
}
-->
</style>

<table width="458" border="0" align="center" cellpadding="5" cellspacing="0">
  <tr>
    <td width="261" height="117" align="left" valign="bottom">log in </td>
    <td width="291" align="left" valign="bottom">sgin up</td>
  </tr>
  <tr>
    <td height="155" align="left" valign="top"><span class="font">Email</span><br />
      <input class="txtstyle" type="text" id="email" />//CREATE INPUT WITH TYPE=TEXT AND ID=EMAIL
      <br />
      <span class="font">Password</span><br />
      <input class="txtstyle" type="password" id="pass" />//CREATE INPUT WITH TYPE=PASSWORD AND ID=PASS
      <br />
      <input type="button" class="loginbutton" id="login" onclick="return false" onmousedown="javascript:login();" value="login"/>//CREATE INPUT WITH TYPE=BUTTON AND ONECE THE BUTTON IS CLICKED JAVASCRIPT:LOGIN() WILL RUN
      <br />
      <div id="result" class="result"></div></td>
    <td width="291" align="left" valign="top">SIGN UP FORM WILL BE HERE</td>
  </tr>
</table>
PARSE.PHP
<?php
include_once "mysql.php";
if($_POST['action']=="login"){
$email1 = $_POST['logname'];//$email1 = $('#email').val();
$pass = $_POST['logpass'];//$pass =  $('#pass').val();
if($email1 ==""){echo'Please enter your email'; }//if $email1 has no value show Please enter your email
else{//if $email1 has value
$sql = mysql_query("SELECT * FROM members WHERE email='$email1'");
$email_check = mysql_num_rows($sql); //check if $email1 value exist in the table
if($email_check == 1){//if exist proceed
  
while($row = mysql_fetch_array($sql)){
$password = $row["password"];//get the password
if($pass == ""){echo 'Please enter your password';}//if $pass has no value show Please enter your password
else if(md5($pass) != $password){echo 'Your password is incorrect';}//if encrypted $pass value not equal to $password show Your password is incorrect
else{//if encrypted $pass value equal to $password the proceed
 //create sessions for the table values
$_SESSION['id']; 
$_SESSION['firstname']; 
$_SESSION['lastname'];  
$_SESSION['email']; 
echo'<script>window.location = "profile.php"</script>';
exit(); 
     }
    }
   }
   else if($email_check != 1){//if doesnt exist show Email is incorrect
   echo 'Email is incorrect';
   }
  }
}
else{echo'<script>window.location = "index.php"</script>';}
?>
PROFILE.PHP
<?php
session_start(); // Must start session first 
include_once "mysql.php";
if (isset($_SESSION['id'])) {  
$id = $_SESSION['id']; 
echo'you are logged in';
 }
else {echo 'you are not logged in';}
?>

Saturday, June 18, 2011

HOW TO CREATE A PAGE MARKUP WITH CSS3 AND JQUERY

<style type="text/css">
<!--
body{
}
.menubar{
 height: 25px;
 width: 450px;
 border-top-left-radius: 10px;
 border-top-right-radius: 10px;
 background-color: #F9F9F9;
 padding: 5px;
 border-top-width: 1px;
 border-right-width: 1px;
 border-left-width: 1px;
 border-top-style: solid;
 border-right-style: solid;
 border-left-style: solid;
 border-top-color: #CCCCCC;
 border-right-color: #CCCCCC;
 border-left-color: #CCCCCC;
 border-bottom-width: 1px;
 border-bottom-style: solid;
 border-bottom-color: #CCCCCC;
 overflow: visible;
}
.button{
 border: 1px solid #CCCCCC;
 border-top-left-radius: 10px;
 border-top-right-radius: 10px;
 display: inline-block;
 font-family: Arial, Helvetica, sans-serif;
 font-size: 12px;
 color: #333333;
 margin-right: 5px;
 text-align: center;
 width: 65px;
 background-color: #E5E5E5;
 text-decoration: none;
 height: 17px;
 padding-top: 6px;
 padding-right: 5px;
 padding-bottom: 6px;
 padding-left: 5px;
}
.selbutton{
 border-top-left-radius: 10px;
 border-top-right-radius: 10px;
 display: inline-block;
 font-family: Arial, Helvetica, sans-serif;
 font-size: 12px;
 color: #333333;
 margin-right: 5px;
 text-align: center;
 width: 65px;
 background-color: #FFFFFF;
 text-decoration: none;
 height: 18px;
 padding-top: 6px;
 padding-right: 5px;
 padding-bottom: 6px;
 padding-left: 5px;
 border-top-width: 1px;
 border-right-width: 1px;
 border-left-width: 1px;
 border-top-style: solid;
 border-right-style: solid;
 border-left-style: solid;
 border-top-color: #CCCCCC;
 border-right-color: #CCCCCC;
 border-left-color: #CCCCCC;
 overflow: visible;
 visibility: visible;
}

.content{
 height: 27px;
 width: 450px;
 border-bottom-left-radius: 10px;
 border-bottom-right-radius: 10px;
 background-color: #FfFfFf;
 padding: 5px;
 border-right-width: 1px;
 border-bottom-width: 1px;
 border-left-width: 1px;
 border-right-style: solid;
 border-bottom-style: solid;
 border-left-style: solid;
 border-right-color: #CCCCCC;
 border-bottom-color: #CCCCCC;
 border-left-color: #CCCCCC;
}
-->
</style>
<script type="text/javascript" src="js/jquery-1.4.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
 $('#Tab2').css('display', 'none');//hide tab2 div
 $('#Tab3').css('display', 'none');//hide tab3 div
});

function tab1(){//once tab1 clicked on
 $('a').removeClass("selbutton");//remove .selbutton class from all linkes
 $('a').addClass("button");//add .button class to all linkes
 $('#b1').removeClass("button");//remove .button
 $('#b1').addClass("selbutton");//add .selbutton (this button will selected)
 $('#Tab2').css('display', 'none');//hide tab 2
 $('#Tab3').css('display', 'none');//hide tab 3
 $('#Tab1').css('display', 'inline-block');//show tab 1
 }
 function tab2(){//once tab2 clicked on
 $('a').removeClass("selbutton");//remove .selbutton class from all linkes
 $('a').addClass("button");//add .button class to all linkes
 $('#b2').removeClass("button");//remove .button
 $('#b2').addClass("selbutton");//add .selbutton (this button will selected)
 $('#Tab1').css('display', 'none');//hide tab 1
 $('#Tab3').css('display', 'none');//hide tab 3
 $('#Tab2').css('display', 'inline-block');//show tab 2
 }
 function tab3(){//once tab3 clicked on
 $('a').removeClass("selbutton");//remove .selbutton class from all linkes
 $('a').addClass("button");//add .button class to all linkes
 $('#b3').removeClass("button");//remove .button
 $('#b3').addClass("selbutton");//add .selbutton (this button will selected)
 $('#Tab1').css('display', 'none');//hide tab 1
 $('#Tab2').css('display', 'none');//hide tab 2
 $('#Tab3').css('display', 'inline-block');//show tab 2
 }
</script>

<div class="menubar"><a id="b1" href="#" class="selbutton" onclick="return false" onmousedown="javascript:tab1();">Tab1</a><a id="b2" href="#" class="button" onclick="return false" onmousedown="javascript:tab2();">Tab2</a><a id="b3" href="#" class="button" onclick="return false" onmousedown="javascript:tab3();">Tab3</a></div>
<div class="content"><div id="Tab1">tab1 is shown tabs 2 & 3 are hidden</div><div id="Tab2">tab2 is shown tabs 1 & 3 are hidden</div><div id="Tab3">tab3 is shown tabs 2 & 1 are hidden</div></div>

Friday, June 17, 2011

HOW TO GET FLASH MEDIA SERVER TO WORK WITH YOUR LOCAL SERVER

I would assume that you have already installed flash media server without apache. So what you would do is go to  this folder   Adobe\Flash Media Server 3\conf\_defaultRoot_ and look for the file called Adaptor.xml on line 42 you would set  ctl_channel="127.0.0.1:19350" and in lines   
        144      <Redirect enable="false" maxbuf="16384">
145 <Host port="80">:8080</Host>
146 <Host port="443">:8443</Host>
147    </Redirect>
same with lines 182 to 185.
and then save it. after that you would go to the text file called fms in the  Adobe\Flash Media Server 3\conf\ and set the  ADAPTOR.HOSTPORT = 127.0.0.1:1935 and then save the file.
now with everything done you can enjoy your flash media server