PHP入门

php+apache+mysql大法好.
被网络对抗作业逼疯(吐血


帮助手册

声明变量

1
2
3
4
5
6
7
8
9
10
<?php
$var = 100;
$var2 = 200;
const var3 = 300;
echo $var+$var2;
echo '<br>';
echo var3;
define('var4', 9000);//宏定义
echo var4;
?>

声明函数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
function test($name){
echo 'hello php<br>';
echo 'hello tbl<br>';
echo 'hello '.$name.'<br>';//字符串的连接是用.来的
return 100;
}
function muti_var($a, $b){
echo 'a = '.$a.' b = '.$b.'<br>';
}
function muti_var($a, $b){
echo "a = $a, b = $b";//必须是双引号!单引号全部默认是字符串
}
test('baby');
muti_var(10, 20);

switch

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
function level($score){
echo $score/10;
$result = 'bad';
switch ((int)($score/10)){
case 10:
case 9:
$result = 'great';
break;
case 8:
case 7:
$result = 'not bad!';
break;
default:
$result = 'bad';
break;
}
return $result;
}
echo level(99);

画图

1
2
3
4
5
6
<?php
$img = imagecreate(400, 300);
imagecolorallocate($img, 255, 255, 255);
imageellipse($img, 200, 200, 50, 50, imagecolorallocate($img, 255, 0, 0));
header('Content-type: image/png');//mime type对应表
imagepng($img);

登陆系统

前端的显示界面

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>login</title>
</head>
<body >
<form action="test.php" method = "post">
<div>name:
<input type = "text" name = "name">
</div>
<div>password:
<input type = "password" name = "password">
</div>
<input type = "submit" value ="login">
</form>
</body>
</html>

后端连接数据库

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
<?php
/**
* Created by PhpStorm.
* User: 宝宝天龙
* Date: 2017/12/18
* Time: 14:20
*/
if (!isset($_POST['name'])) {
die('you don\'dont type anything man.');
}
if (!isset($_POST['password'])) {
die('you don\'dont type anything man.');
}
$name_get = $_POST['name'];
$password_get = $_POST['password'];
//printf("%s %s", $name_get, $password_get);
$conne = @mysqli_connect('localhost', 'root', '');
if($conne){
mysqli_select_db($conne, 'test');
// $str = "'s Hertogenbosch";
// echo $str."<br>";
// $name_get = mysqli_escape_string($conne, $str);
// echo $name_get.'<br>';
$result = mysqli_query($conne, "SELECT * FROM test where name = '$name_get' ");
// print_r($result.'<br>');
// $result_arr = mysqli_fetch_assoc($result);
// print_r($result_arr);
// echo '<br>';
// echo ''.mysqli_num_rows($result);
$tot = mysqli_num_rows($result);
// print_r($result_arr['name']);
$flag = false;
for($i=0; $i < $tot; $i++){
$result_arr = mysqli_fetch_assoc($result);
if ($result_arr['name'] == $name_get && $result_arr['password'] == $password_get){
$flag = true;
break;
}
}
if($flag == true){
echo "login successfully!";
}
else{
echo "unsuccessfully!".'<br>'."hey man";
}
}
else
echo '未连接数据库<br>';
文章目录
  1. 1. 声明变量
  2. 2. 声明函数
    1. 2.0.1. switch
  • 画图
  • 登陆系统
    1. 1. 前端的显示界面
    2. 2. 后端连接数据库
  • {{ live2d() }}