-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
138 lines (119 loc) · 3.18 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<html>
<title>
My Test Page
</title>
<body>
<?php
$br = "<br>";
$text = "Hello php world ...!";
$sql = "And mysql world ...!";
echo $text . '<br>' . $sql.'<br>';
print(strlen($sql).'<br>');
echo strpos($sql, "world").'<br>';
$d = date("D");
echo $d.$br;
if($d == "Fri")
{
echo "Have a Nice weekend!".$br;
}elseif($d == "Sun"){
echo "Have a Nice Sunday";
}else{
echo "Have a Nice day!".$br;
}
//switch ,while,do while, are same as C;
//Array is different for defrence
?>
<br/>Testing form post .....<br/>
<!-- Post data to myget.php $_POST,$_GET,$_COOKIE,get the data from each form,$_REQUEST inlcude all off them-->
<!--<form action="myget.php" method="post"> -->
<form method="post">
Name:<input type="text" name="name"/>
Age: <input type="text" name="age" />
<input type="submit">
</form>
<br/>
Welcome <?php echo $_POST["name"]; ?><br/>
Your age is <?php echo $_POST["age"]; ?> years old! <br/>
<br/>Testing date function.....<br/>
<!-- Test date function -->
<?php
echo date("Y/m/d").$br;//without timestamp display the current date
echo date("Y/M/D").$br;
$tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y"));
echo "Tomorrow is ".date("Y/m/d",$tomorrow).$br;// use timestamp
?>
<br/>Testing include ,require.....<br/>
<!-- Test include ,require -->
<?php
include 'vars.php';
echo "My car is ".$color." ".$car.$br;
//require "phpinfo.php";
?>
<br/>Testing Mysql here.....<br/>
<?php
//Test Mysql here
$mysql_con = mysql_connect("localhost:3306","root","root");
if(!$mysql_con){
die('Can not connect to mysql:'.mysql_error());
}else{
echo 'Connect mysql sucessed!'.$br;
}
if(mysql_query("CREATE DATABASE phpDB",$mysql_con))
{
echo 'Database phpDB created!'.$br;
}else{
echo 'Create phpDB failed:'.mysql_error().$br;
}
mysql_select_db('phpDB');
$table="CREATE TABLE Persons
(
personID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(personID),
FirstName varchar(15),
LastName varchar(15),
City varchar(10),
Age Int
)";
if(mysql_query($table,$mysql_con))
{
echo 'Create table successed!'.$br;
//insert
mysql_query("INSERT INTO Persons (FirstName, LastName,City, Age) VALUES ('Peter', 'Griffin', 'Shenzhen', '35')");
mysql_query("INSERT INTO Persons (FirstName, LastName,City, Age) VALUES ('Glenn', 'Quagmire', 'Shenzhen', '33')");
}else{
echo 'Create table failed:'.mysql_error().$br;
//update
mysql_query("UPDATE Persons SET Age = '36' WHERE FirstName = 'Peter' AND LastName = 'Griffin'");
}
$result = mysql_query('select * from Persons order by Age');
echo "<table border=1>
<tr>
<th>FirstName</th>
<th>LastName</th>
<th>City</th>
<th>Age</th>
</tr>
";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['FirstName'] . "</td>";
echo "<td>" . $row['LastName'] . "</td>";
echo "<td>" . $row['City'] . "</td>";
echo "<td>" . $row['Age'] . "</td>";
echo "</tr>";
}
echo "</table>";
if($mysql_con){
mysql_close($mysql_con);
}
?>
<!-- Testing make xml to dispaly the mysql resualt -->
<br/>Display the mysql table content into xml...<br/>
<form action="xml.php" method="post">
DataBase:<input type="text" name="database" />
Table:<input type="text" name="table" />
<input type="submit" />
</form>
</body>
</html>