分類彙整: Web資料庫範例

[第11堂] 課程範例

login1.php

<html>
<form action="login2.php" method="post" name="form1″><br>
Input your data:<br>
<input name="name" type="text" value=""><br>
<input name="pwd" type="text" value=""><br>
<input name="email" type="text" value=""><br>
<input name="submit" type="submit" value="GO"><br>
</form>
</html>

——————————-

login2.php

<?php
session_start();
$_SESSION[“name"]=$_POST[“name"];
$_SESSION[“pwd"]=$_POST[“pwd"];
$_SESSION[“email"]=$_POST[“email"];
echo “name:".$_SESSION[“name"]."<br>";
echo “pwd:".$_SESSION[“pwd"]."<br>";
echo “email:".$_SESSION[“email"]."<br>";
?>

————————-

WebForm1.aspx

protected void Button1_Click(object sender, EventArgs e)
{
Session.Add(“name", TextBox1.Text);
Session.Add(“pwd", TextBox2.Text);
Session.Add(“email", TextBox3.Text);

//重新導向新的頁面
Response.Redirect(“WebForm2.aspx");
}

————————

WebForm2.aspx

//於page_load執行下列程式碼

if (Session[“name"] != null)
{
Response.Write(“name:" + Session[“name"].ToString()+"<br>");
Response.Write(“pwd:" + Session[“pwd"].ToString() + “<br>");
Response.Write(“email:" + Session[“email"].ToString() + “<br>");
}
else
{
Response.Write(“no session data");
}

[第五堂] PHP POST & GET 九九乘法範例

GET    http://140.112.31.82/example.php?val=9

<?php
if(count($_GET)>0){
for($i=1;$i<=$_GET[“val"];$i++){
for($j=1;$j<=$_GET[“val"];$j++){
echo “$i*$j=".$i*$j."<br>";
}
echo “=======<br>";
}
}
?>

POST    http://140.112.31.82/example2.php

<form action="" method="post" name="form1″><br>
Please input value:
<input name="val" type="text" value="9″>
<input name="submit" type="submit" value="ok"><br>

<?php
if(count($_POST)>0){
for($i=1;$i<=$_POST[“val"];$i++){
for($j=1;$j<=$_POST[“val"];$j++){
echo “$i*$j=".$i*$j."<br>";
}
echo “=======<br>";
}
}
?>

[第四堂] php & sqlite 範例

<form action="" method="post" name="form1″><br>
Input address book data:<br>
<input name="name" type="text" value="shinder"><br>
<input name="phone" type="text" value="0918981520″><br>
<input name="address" type="text" value="Taipei"><br>
<input name="submit" type="submit" value="Add"><br>

<?php

//建立資料連線物件
$pdo = new PDO(“sqlite:mydb.sqlite");

$pdo->exec(“CREATE TABLE address_book (
sid INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL ,
name VARCHAR,
phone VARCHAR,
address VARCHAR,
creation_date DATETIME DEFAULT CURRENT_TIMESTAMP)");
if(count($_POST)>0) {
// 準備新增資料的語法
$name = $_POST[“name"];
$phone = $_POST[“phone"];
$address = $_POST[“address"];
$pdo->exec(“INSERT INTO ‘address_book’ (‘name’, ‘phone’, ‘address’ )
VALUES( ‘$name’, ‘$phone’, ‘$address’)");
}

$pdoStatement = $pdo->prepare(“SELECT * FROM address_book");
$pdoStatement->execute();
$arr;
while($row = $pdoStatement->fetch(PDO::FETCH_ASSOC) ) {
print_r( $row );
}