day1
在选择就业还是考验的路上不坚定是自己最迷茫的表现,但是我还是会继续下去继续学习自己喜欢做的事
part1:
这是刚刚开始学习的第一天,无非就是像在学校的基础语法过了一下详情请看代码
<?php
//必须要有这个进行代码包裹
// /*用于注释一个段落双斜线只能注释一行
// 输出内容使用两个函数echo和print
use LDAP\Result;
echo "你好php<br/>";
// 换行符无法被浏览器解析要是用<br/>
print "你好hacker";
//变量
// echo支持逗号拼接输出引号
echo "1111","222","3333<br/>";
echo "1111"."222"."3333<br/>";
// .表示连接符
echo "你好,余额为". 20000 ."元";
//定义变量
$addr="贵州";
echo "你的城市:$addr<br/>";
echo '你的城市:$addr<br/>';
// 双引号表示应用变量,单引号表示字符串,反引号表示命令
$result= `ipconfig`;
$result=iconv("GBK","utf-8",$result);
echo $result;
// 编码格式网页的编码是utf-8操作系统的是GBK
// 在header函数之中写入GBK的响应头header("content-type:text/html;charset='GBK'");
// 使用PHP、内置函数iconv对需要转码的部分进行转码;
// 变量定义
/*
数据类型:字符串,整型(integer),浮点型,布尔,数组(array),对象(null)
命名规范$+字母或者下划线开头加数字,变量名不要用中文全拼应该去使用英文为方便阅读理解
不可以包括空格 语言都是触类旁通的运算符都差不多
*/
// if("100"==100){
// echo "两者相等";//这里可以输出这些都是基于C语言,运算符优先级这些基础都是可以去了解;不需要刻意去记住
// }
//part 2不使用正则表达式去判断输入一个手机号是否有效;
//估计就是使用if else去判断;分支语句还有Switch case只能判断条件恒等的没有更复杂的格式
//循环语句要注意的是 do while foreach:根据数组袁术进行遍历
// $i=date("S");
// while($i <30){
// echo date("Y-m-d");
// }
// $i=1;
// while($i<10){
// echo $i .'<br/>';
// $i++;
// }
//适用于有条件无次数的情况
//也可以使用for($i=1;i<10;i++)比较适合有明确的的循环次数
// $i=date("s");
// if($i<=30){
// ob_flush();//清空缓冲区,直接输出代码存在的sleep的时候进行处理让缓冲区不被阻塞;
// //执行时间不要超过三十秒;
// flush();
// echo date("H-m-d H:i:s") . "<br/>";
// $i=date("s");
// sleep(1);
// }
//PHP时区设置;相差六小时
// 首先是要求去取到字符串的长度还有值我们一起来解决手机号码的解决首先是全部是数字还有位数第一位必须是1?第二位不能是012?
?>
part:实现登录界面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>登录界面</title>
<style>
.login{
text-align: center;
}
.footer{
width: 500px;
height: 50px;
border: solid 0px blue;
margin: auto;
text-align: center;
}
.top-100{
margin-top: 100px;
}
.font-30{
font-size: 30px;
}
input{
width: 300px;
height: 35px;
text-align: center;
border-radius: 5px;
}
button{
width: 310px;
height: 40px;
background-color: blue;
color: whitesmoke;
border-radius: 5px;
}
</style>
</head>
<body >
<div class="login top-100 font-30">登录界面</div>
<form action="login.php" method="POST">
<div class="login">
<input type="text"name="username"/>
</div>
<div class="login">
<input type="password"name="password"/>
</div>
<div class="login">
<input type="text" name="vcode"/>
</div>
<div class="login">
<button type="submit">登录</button>
</div>
</form>
<div class="footer top -100">版权所有是来自于B站蜗牛学院的教学视频</div>
</body>
</html>
上面是使用表单方式提交,下面我们可以使用AJAX方式去提交:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AJAX</title>
<script type="text/javascript" src="jquery-3.4.1.min.js"></script>
<style>
.login{
text-align: center;
}
.footer{
width: 500px;
height: 50px;
border: solid 0px blue;
margin: auto;
text-align: center;
}
.top-100{
margin-top: 100px;
}
.font-30{
font-size: 30px;
}
input{
width: 300px;
height: 35px;
text-align: center;
border-radius: 5px;
}
button{
width: 310px;
height: 40px;
background-color: blue;
color: whitesmoke;
border-radius: 5px;
}
</style>
<script>
function doPost(){
//获取表单元素
var username = $("#username").val();
var password = $("#password").val();
var vcode = $("#vcode").val();
//字符串拼接为一个请求正文
var param="username="+username+"&password"+password+"&vcode";
// window.alert(param);
$.post('login.php',param,function(data){
if(data=="登录成功<br/>"){
window.alert('登录成功');
//页面跳转
location.href="list.php";
}
else {
window.alert("登录失败");
}
});
}
</script>
</head>
<body >
<div class="login top-100 font-30">登录界面</div>
<div class="login">
<input type="text"name="username" id="username"/>
</div>
<div class="login">
<input type="password"name="password" id="password"/>
</div>
<div class="login">
<input type="text" name="vcode" id="vcode"/>
</div>
<div class="login">
<button onclick="doPost()">登录</button>
</div>
<div class="footer top -100">版权所有是来自于B站蜗牛学院的教学视频</div>
</body>
</html>
明天写完后端的PHP再来分享,今天是先把前端的框架搭建好了,要准备的工具包包括XAMPP,Navicat
<?php
/**
* 获取请求的方式:
* GET
* PUST
*/
$username=$_POST['username'];
$password=$_POST['password'];
$vcode=$_POST['vcode'];
/**
* 验证码现行验证
*/
if($vcode!='0000'){
die ("验证码不正确");
}
// echo $username."-". $password."-".$vcode;
/**
* 如何在php之中访问msql是一般使用mysqli还有PDO
* 1.连接到mysql数据库
* 执行SQL语句,
* 处理SQL语句的结果
* 关闭数据库连接所有的io操作都要实现打开与关闭:文件读写,网络访问,数据库
*/
$conn =mysqli_connect('192.168.43.147','luo','123p-0p-0p-0','learn') or die;//数据库连接
mysqli_query($conn,"set names uf8");//修改编码格式
$sql="select *from user where username='$username'and password='$password'";
$result=mysqli_query($conn,$sql);//获取查询信息作为结果;
//result==1表示查询成功;
if(mysqli_num_rows($result)==1){
echo "登录成功<br/>";
}else{
echo "登录失败<br/>";
}
//关闭数据库
mysqli_close($conn);
?>