Archive for 六月, 2015

29
六月

暑期營程式設計 06/29: ex1

   Posted by: admin    in 104(暑)程式設計營

//ex1.htm
<h1>Ex1</h1>
<form action="ex1.php" method="post">
姓名<input name="SName" type="text" />
<input name="Sbumit" type="submit"  value="送出"/>
</form>
//ex1.php
<?php
$Var1=$_POST["SName"];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>PHP POST</title>
</head>
 
<body>
<h1>接收資訊</h1>
<?php echo $Var1; ?>, 您好。
</body>
</html>

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags:

8
六月

程式設計二程式 06/08: ex9

   Posted by: admin    in 103(下)程式設計(二)

//ex9.php
<?php
$db = new PDO('mysql:host=localhost;dbname=testdb;charset=utf8', 'phpuser', '23323456');
if (isset($_POST["Submit"]))
{
   //讀入表單參數
   $email = $_POST["EMail"];
   $message = $_POST["Message"];
   $msgdate = date("Y-m-d H:i:s");
   //寫入資料庫
   $query = "INSERT INTO guestbook(email, message, msgdate) VALUES ('$email','$message','$msgdate')";
   $result = $db->exec($query);
}
 
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ex9:Guestbook</title>
</head>
 
<body>
<h1>Ex9:Guestbook</h1>
<form action="ex9.php" method="post">
<table border="1" width="100%">
<tr>
<td colspan="2">請問您有何建議</td>
</tr>
<tr>
<td >EMail:</td><td ><input type="text" name="EMail" /></td>
</tr>
<tr>
<td >留言:</td><td ><input type="text" name="Message" /></td>
</tr>
<tr><td> <input type="submit" name="Submit" value="送出留言" /></td><td></td>
</tr>
</table>
</form>
<h1>留言內容</h1>
<hr />
<table border="1" width="100%">
<?php
$query="SELECT * FROM guestbook ORDER BY msgdate DESC LIMIT 10";
$stmt = $db->prepare($query);
 
$stmt->execute();
while($row = $stmt->fetch()){
   print "<tr>
<td>".$row["gid"]."</td>
<td>".$row["email"]."</td>
<td>".$row['message']."</td>
<td>".$row['msgdate']."</td>
</tr>";
}
?>
</table>

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , , ,

1
六月

程式設計二程式 06/01: ex8

   Posted by: admin    in 103(下)程式設計(二)

//ex8.php
<?php
session_start();//網頁要記錄有登錄,都是使用 session變數來記錄
if (!isset($_SESSION['auth']))
{
	header('Location: ex8-login.php');
	exit;
}
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ex8</title>
</head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<!-- Optional theme -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css" rel="stylesheet" type="text/css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<body>
<ul class="nav nav-pills">
  <li role="presentation" class="active"><a href="#">Ex8</a></li>
  <li role="presentation"><a href="ex8-logout.php">登出</a></li>
</ul>
<p><img src="title_2.jpg" width="550" height="77" /></p>
 
//ex8-login.php
<?php
$message ="請輸入密碼";
if(isset($_POST["Submit"])){
 $Usename=$_POST["Usename"];
 $Password=$_POST["Password"];
 if ($Usename == "abc" && $Password =="123")
 {
   session_start();
   $_SESSION['auth'] = true;//認證成功,設定一個session變數
   header('Location: ex8.php');
   exit;
 }
 else
 {
   $message="帳號或密碼錯誤";
 }
}
?>
 
<h1>Ex8-login</h1>
<form action="ex8-login.php" method="post">
<table width="200″ border="1″>
<tr>
<td>帳號</td>
<td><input type="text" name="Usename" ></td>
<td><?php echo $message?> </td>
</tr>
<tr>
<td>密碼</td>
<td><input type="password" name="Password"></td>
<td><input type="submit" name="Submit" value="登入" /></td>
</tr>
</table>
</form>
//ex8-logout.php
session_start();
unset($_SESSION['auth']);
header('Location: ex8-login.php');
exit;

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , , ,