留言板問題 ~請幫忙...

edited 七月 2014 in PHP新手區
<
留言板
>
<?php include ("outsideNav.php")?>
<?php include("counter.php");
 include("mysql_connect.inc.php");
 ?>
 <?php $mytable='guestbook';
	  		$result=mysql_query("select * from `".$mytable."` order by num DESC");
	  		$numrows=mysql_query("select count(*)  from `".$mytable."");
	  		$a=mysql_fetch_array($numrows);
	 ?>
<!Doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link rel="stylesheet"   type="text/css"  href="style.css">
		<script type="text/javascript" src="time.js"></script>
</head>
<body	 onload="ShowTime()">
		<div		id="wrap">
		<div		id="head">
		</div>
		<div		id="content">
		<div		id="sideNav">
			<?php sideNav(8)?>
		</div>
		<div		id="main" >
	  	 <?php
	  		echo "共有 ".$a[0]." 筆留言";
	  		if ($a[0]>0){
			echo '<ol>';
			$i=1;
			while ($row = mysql_fetch_array($result)){
				if ($i%2==0){
					$liclass='even';
				}else{
					$liclass='odd';
				}
				echo "<li class='message $liclass'><p><strong>".$row['name']."</strong>
								<em> 於 ".$row['time']."  留言</em></p>
								<p>".$row['main']."</p></li>";
						$i++;	
			}	
			echo '</ol>';
		}
		
	  	 ?>
	  
		</div>
		</div>
		<div		id="foot">
			 <form method="POST"  name="form1" action="message.php">
					匿名:<input type="text" name="name" size="20" ><br>
					內容:<textarea name="main" cols="45" rows="5"></textarea><br>
					<input type="submit" value="送出" >
					<input type="reset" value="reset" >
	  	 </form>
	  	 <?php 
	  	 	
	  	 	$name=' ';
	  	 	$main=' ';
	  	 	
	  	 	if ( ! empty ($_POST['name'] ) && ! empty ($_POST['main']) ){
				$name=$_POST['name'];
				$main =$_POST['main'];
				
				date_default_timezone_set('Asia/Taipei');
				$sql2="insert into `".$mytable."` (`name`,`main`,`time`) value ('".$name."','".$main."','".date("Y-m-d h:i:s")."')";
				if(mysql_query($sql2)){
					echo '已成功新增留言<br>';
				}else{
					echo '無法新增留言<br>';
				}
			}
			if (empty ($_POST['name'] ) ) {
				$errmsg='您忘記輸入名稱<br>';
			}else{
				$errmsg='您忘記輸入內容<br>';
			}
			?>
	  	
		<?php cnt();?>
		<div id="showbox"></div>
		</div>
		</div>
</body>
</html>

<
留言板回覆
>
<?php include ("insideNav.php")?>
<?php include("counter.php");
 include("mysql_connect.inc.php");
 ?>
 <?php 
 $sql="select * from guestbook where num='".$_GET['pid']."' ";
 $result = mysql_query($sql);
 $row = mysql_fetch_row($result);
 ?>

<!Doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link rel="stylesheet"   type="text/css"  href="style.css">
		<script type="text/javascript" src="time.js"></script>
</head>
<body	 onload="ShowTime()">
		<div		id="wrap">
		<div		id="head">
		</div>
		<div		id="content">
		<div		id="sideNav">
			<?php insideNav(7)?>
		</div>
		<div		id="main" >
	  		
	  	 
	  	 <?php 
	  	echo " <form method=\"POST\"  name=\"form1\" action=\"reply.php\">";
	  	echo " ID:<input type=\"text\" value=\"jackjow\" ><br>";
	  	echo "內容:<textarea name=\"main\" cols=\"45\" rows=\"6\" required ></textarea><br>";
	  	echo "<input type=\"submit\" value=\"送出\" > ";
	  	echo "<input type=\"reset\" value=\"reset\" >";
	  	echo "</form>";
	  	 		
	  	 		
				date_default_timezone_set(' Asia/Taipei ');
				
				
				$name=$_POST['name'];
				$reply=$_POST['reply'];
				$num=$_POST['num'];
				
				$sql2="select * from res";
				$result = mysql_query($sql2);
				$row = mysql_fetch_row($result);
				
				if(isset ($_POST['name']) && isset($_POST['reply'])){ <---------這一行條件寫下去就不能寫入資料庫了
				$sql2="insert  into `res` set  name='".$name."',reply='".$reply."',num='".$row['0']."',time='".date("Y-m-d h:i:s" )."'  ";			
				echo "$sql2";
				
				if(mysql_query($sql2) ){
					echo '已成功回覆留言<br>';
					echo '<meta http-equiv="refresh" content="1 ; url=msg.php"/>';
				}else{
					echo '無法回覆留言<br>';
				}
			
				}
			?>
	  
		</div>
		</div>
		<div		id="foot">

		<?php cnt();?>
		<div id="showbox"></div>
		</div>
		</div>
</body>
</html>
<----顯示留言板---->
<?php  include ("insideNav.php")?>
<?php include("counter.php");
 include("mysql_connect.inc.php");
?>	
 <?php $mytable='guestbook';
	  		$result=mysql_query("select * from `".$mytable."`  order by num DESC");
	  		$numrows=mysql_query("select count(*)  from `".$mytable."");
	  		$a=mysql_fetch_array($numrows);
	 ?>
<!Doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link rel="stylesheet"   type="text/css"  href="style.css">
		<script type="text/javascript" src="time.js"></script>
</head>
<body 	onload="ShowTime()">
		<div		id="wrap">
		<div		id="head">
		</div>
		<div		id="content">
		<div		id="sideNav">
			
				<?php  insideNav(7)?>		
		</div>
		<div		id="main" >
		
	   <?php session_start(); ?>
			<?php
			echo '<ol>';
			if(isset($_SESSION['id'])){
				echo "共有 ".$a[0]." 筆留言";
				if ($a[0]>0){
					$i=1;
					while ($row = mysql_fetch_array($result)){
						if ($i%2==0){
							$liclass='even';
						}else{
							$liclass='odd';
						}
						echo "<li class='message $liclass'><p><strong>".$row['name']."</strong>
												<em> 於 ".$row['time']." 留言</em> <span class='p1'> <a href=\"reply.php?pid=".$row['0']."\">回覆</a></span></p>
												<p>".$row['main']."</p>
												<p>".$row['reply']."</p></li>";
												$i++;
					}
					
						}
						echo '</ol>';
				}
			?>
		</div>
		</div>
		<div		id="foot">
		<?php cnt();?>
		<div id="showbox"></div>
		</div>
		</div>
</body>
</html>
Sign In or Register to comment.