XtGem Forum catalog
Create New Topic
Topic:
Detail:
Name:
Email:
  
"; }elseif (isset($_GET['type']) && $_GET['type'] == "post") { $topic=$_POST['topic']; $detail=$_POST['detail']; $name=$_POST['name']; $email=$_POST['email']; $datetime=date("d/m/y h:i:s"); //create date time $sql="INSERT INTO $tbl_name(topic, detail, name, email, datetime)VALUES('$topic', '$detail', '$name', '$email', '$datetime')"; $result=mysql_query($sql); if($result){ echo "Successful
"; echo "View your topic"; }else { echo "Error Posting."; } }elseif (!isset($_GET['type'])) { $sql="SELECT * FROM $tbl_name ORDER BY id DESC"; // OREDER BY id DESC is order result by descending $result=mysql_query($sql); echo ""; while($rows=mysql_fetch_array($result)){ // Start looping table row echo ""; } echo "
#TopicViewsRepliesDate/Time
".$rows['id']."".$rows['topic']."
".$rows['view']."".$rows['reply']."".$rows['datetime']."
Create New Topic
"; }elseif (isset($_GET['type']) && $_GET['type'] == 'view') { // get value of id that sent from address bar $id=$_GET['id']; $sql="SELECT * FROM $tbl_name WHERE id='$id'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); echo "
".$rows['topic'].">
".$rows['detail']."
By : ".$rows['name']." Email : ".$rows['email']."
Date/time : ".$rows['datetime']."

"; $tbl_name2="forum_replies"; // Switch to replies table $sql2="SELECT * FROM $tbl_name2 WHERE thread_id='$id'"; $result2=mysql_query($sql2); while($rows=mysql_fetch_array($result2)){ echo "
ID:".$rows['a_id']."
Name:".$rows['a_name']."
Email:".$rows['a_email']."
Answer:".$rows['a_answer']."
Date/Time:".$rows['a_datetime']."

"; } $sql3="SELECT view FROM $tbl_name WHERE id='$id'"; $result3=mysql_query($sql3); $rows=mysql_fetch_array($result3); $view=$rows['view']; // if have no counter value set counter = 1 if(empty($view)){ $view=1; $sql4="INSERT INTO $tbl_name(view) VALUES('$view') WHERE id='$id'"; $result4=mysql_query($sql4); } // count more value $addview=$view+1; $sql5="update $tbl_name set view='$addview' WHERE id='$id'"; $result5=mysql_query($sql5); echo "
Name:
Email:
Answer:
 
"; }elseif (isset($_GET['type']) && $_GET['type'] == "reply") { // Get value of id that sent from hidden field $id=$_POST['id']; // Find highest answer number. $sql="SELECT MAX(a_id) AS Maxa_id FROM $tbl_name WHERE thread_id='$id'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); // add + 1 to highest answer number and keep it in variable name "$Max_id". if there no answer yet set it = 1 if ($rows) { $Max_id = $rows['Maxa_id']+1; }else { $Max_id = 1; } // get values that sent from form $a_name=$_POST['a_name']; $a_email=$_POST['a_email']; $a_answer=$_POST['a_answer']; $datetime=date("d/m/y H:i:s"); // create date and time // Insert answer $sql2="INSERT INTO $tbl_name(thread_id, a_id, a_name, a_email, a_answer, a_datetime)VALUES('$id', '$Max_id', '$a_name', '$a_email', '$a_answer', '$datetime')"; $result2=mysql_query($sql2); if($result2){ echo "Successful
"; echo "View your answer"; // If added new answer, add value +1 in reply column $tbl_name2="forum_question"; $sql3="UPDATE $tbl_name2 SET reply='$Max_id' WHERE id='$id'"; $result3=mysql_query($sql3); } else { echo "ERROR"; } } ?> PHP Free Code