当前位置: 首页 > news >正文

高碑店做网站的公司网上销售

高碑店做网站的公司,网上销售,wordpress 汉化模版,应用公园制作app教程视频一、连接数据库基本函数 mysqli_connect(); 作用&#xff1a;创建数据库连接&#xff0c;打开一个新的mysql的连接。传参顺序&#xff1a;数据库地址、数据库账号、数据库密码 <?phpecho mysqli_connect("localhost",root,root) ?> /*结果&#xff1a;F…

一、连接数据库基本函数

  1. mysqli_connect();
    1. 作用:创建数据库连接,打开一个新的mysql的连接。
    2. 传参顺序:数据库地址、数据库账号、数据库密码
<?phpecho mysqli_connect("localhost",'root','root')
?>  
/*结果:Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in C:\Users\Administrator\Desktop\网络安全\php\project_01\php_connect.php:2 Stack trace: #0 {main} thrown in C:\Users\Administrator\Desktop\网络安全\php\project_01\php_connect.php on line 2*/
  1. 寻错
    1. 翻译错误为:致命错误:未捕获错误:调用未定义的函数mysqli_connect()
    2. 出现错误原因:未配置php.ini
  2. 解决方法
    1. 参考:https://blog.csdn.net/sxudong2010/article/details/83277285
  3. 重新测试连接
<?php
$conn=mysqli_connect("localhost","root","root");
if($conn){echo"ok";
}else{echo"error";
}
//phpinfo();
?>  
  1. 效果图:

image.png

  1. mysqli_select_db()
    1. 作用:选择需要的数据库
    2. 传参顺序:mysqli对象,数据库名
mysqli_select_db($conn, "php"); #选择名为php的数据库
  1. mysqli_query()
    1. 作用:可以对数据库中的表进行增删改查
    2. 传参顺序:mysqli对象,SQL语句
# 修改编码
mysqli_query($conn, "SET NAMES utf8");
# $GLOBALS是将conn变量赋予全局属性
# 查询user表中userName字段为abc的数据
# 返回值为:mysqli_result对象
mysqli_query($GLOBALS["conn"], "select * from user where userName = abc")
  1. mysqli_fetch_row()和mysqli_fetch_all()
    1. 区别:
      1. row()只返回一条数据,适合有条件的查询,(如返回Array时,为一维数组)
      2. all()返回查询到的所有数据,使用列表展示功能,(如返回Array时,为二维数组)
    2. 作用,接收查询数据并并以多种形式返回,
    3. 传参顺序:mysqli_result对象
# 参数为:mysqli_query()函数返回的 mysqli_result对象
# 返回结果为:Array
echo mysqli_fetch_all( mysqli_query($GLOBALS["conn"], "select * from user "))
echo mysqli_fetch_row( mysqli_query($GLOBALS["conn"], "select * from user where userName=123"))

二、案例实现

1、功能说明

该案例主要功能为用户登录和修改密码功能

2、涉及知识

  1. php变量作用域的范围
  2. php对于Session的存储、修改和销毁
  3. php对于字符串Base64编码和解码的应用
  4. php对于字符串判空、去空、去特殊值的处理
  5. php对于Mysql的如何连接、选择数据库、增删改查等功能

3、页面分布

  1. index.php:登录页
  2. index.php:个人中心页
  3. register.php:注册页
  4. db.php:对于数据库一系列操作
  5. utril.php:工具方法
  6. style.css:页面通用css样式

4、db.php

<?php
# 创建一次新的mysql连接
$conn = mysqli_connect("localhost", "root", "root") or dir("数据库连接失败");
# var_dump($conn);
#连接上名为php的数据库
mysqli_select_db($conn, "php");
# 修改编码
mysqli_query($conn, "SET NAMES utf8");
/*** 判断用户是否存在* $name:用户名* return:返回存在的数据数组* */
function isQueryUserName($name){return mysqli_fetch_row( mysqli_query($GLOBALS["conn"], "select * from user where userName = '$name'"));
}
/** 更新密码* $userName:用户名* $password :密码* */
function updatePassword($userName,$password){$password = base64_encode($password);return mysqli_query($GLOBALS['conn'], "update user set password = '$password' where userName = '$userName'");
}?>

5、util.php

<?php
/*判断数据是否为空* */
function isEmpty($value){return !empty($value)?true:false;
}
/** 去除多余格式* trim:去除左右两边空格* stripslashes:去除反斜杠* htmlspecialchars:把预定义的字符转换为 HTML 实体* 预定义的字符是:(和号)成为 &amp;" (双引号)成为 &quot;' (单引号)成为 '< (小于)成为 &lt;> (大于)成为 &gt;&** */
function outFormat($value){$value = trim($value);$value = stripslashes($value);$value = htmlspecialchars($value);return $value;}//    echo base64_encode("admin"); // 编码#  echo base64_decode("dmFyaW4="); // 解码
/** 匹配8位由大写或小写或数字* */
function passwordReg($password){return preg_match("/^[a-zA-Z0-9]{8}$/", $password);
}

6、style.css

*{padding:0px;margin:0px;
}
.box{margin: 100px auto;background: linear-gradient(135deg, #d3e4f5, #0088a9, #00c9a7, #92d5c6, #ebf5ee)  repeat-x  ;width:600px;height:500px;border:1px solid #f5f5f5;border-radius: 15px;box-shadow: 10px 10px 10px #f5f5f5;color: white;
}
h2{text-align: center;margin: 20px 0px;
}
label{margin: 20px 0px;display: inline-table;
}
form{text-align: center;
}
input{color: black;
}

7、login.php

  1. 代码
<?php# 开启sessionsession_start();
# 包含
include './db.php';
include './util.php';
$userName=$password='';
# 检测
if(isset($_POST['loginSubmit'])){$userName =outFormat( $_POST['userName']);$password =outFormat($_POST['password']);# 判空if(isEmpty($userName) && isEmpty($password)){# 查询$userInfoArray= isQueryUserName($userName);# 比对数据if($userInfoArray!=null&&  $userInfoArray[1]== $userName && base64_decode($userInfoArray[2])== $password){echo "<script>alert('登录成功!');</script>";# 存session$_SESSION["userName"]=$userName;//               echo  $_SESSION["userName"];echo "<script>window.location.href='index.php';</script>";}else{echo "<script>alert('用户信息错误,请重试!');</script>";}}else{echo "<script>alert('请将信息填写完整!');</script>";}
}?><!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Login</title><link href="./style.css" type="text/css" rel="stylesheet"></head><body><div class="box"><h2>登录</h2><form action="./login.php" method="POST"><label > 用户名:<input type="text" name="userName" value="<?php echo $userName?>"></label><br><label >&nbsp;&nbsp; &nbsp;码:<input type="password" name="password" value="<?php echo $password?>"></label><br><input type="submit" name="loginSubmit" value="登录" style="width:60px;height: 30px;color: black;margin-top: 100px"><br><p style="margin-top: 20px;color: black;font-size: 14px"><a href="#" style="color: green">注册</a></p></form></div></body></html>
  1. 效果

image.png

8、index.php

  1. 代码
<?phpsession_start();include './db.php';include './util.php';$userName=$password=$confirmPassword='';$userName=$_SESSION['userName'];if($userName==null){echo "<script>window.location.href='login.php';</script>";}$password= base64_decode(isQueryUserName($userName)[2]);if(isset($_POST['updateSubmit'])){$password = $_POST['password'];$confirmPassword = $_POST['confirmPassword'];echo $password;echo $confirmPassword;if(isEmpty($password)&& isEmpty($confirmPassword)){if(passwordReg($password) && $password == $confirmPassword){if (updatePassword($userName, $password)==true) {echo "<script>alert('用户密码更新成功 ')</script>";session_destroy();echo "<script>window.location.href='login.php';</script>";}}else{echo "<script>alert('密码格式错误,请重试!')</script>";}}else{echo "<script>alert('请将信息填写完整')</script>";}}
?>
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>个人中心</title><link href="./style.css" type="text/css" rel="stylesheet">
</head>
<body>
<div class="box"><h2>个人中心</h2><form action="#" method="post"><label > 欢迎您,<span style="font-weight: bold" ><?php echo $userName?></span></label><br><label >&nbsp;&nbsp; &nbsp;码:<input type="password" name="password" value="<?php echo  $password?>"></label><br><label > 确认密码:<input type="password" name="confirmPassword" value="<?php echo  $confirmPassword ?>"></label><br><input type="submit" name="updateSubmit" value="修改" style="width:60px;height: 30px;color: black;margin-top: 100px"><br></form>
</div></body>
</html>
  1. 效果

image.png

9、register.php

  1. 注:注册页面并为实现注册功能,大致功能代码与index.php页面类似。
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Login</title><link href="./style.css" type="text/css" rel="stylesheet"></head>
<body>
<div class="box"><h2>注册</h2><form action="#" method="post"><label > 用户名:<input type="text" name="userName" value="用户名"></label><br><label >&nbsp;&nbsp; &nbsp;码:<input type="password" name="password" value="密码"></label><br><input type="submit" name="loginSubmit" value="登录" style="width:60px;height: 30px;color: black;margin-top: 100px"><br><p style="margin-top: 20px;color: black;font-size: 14px"><a href="#" style="color: green">注册</a></p></form>
</div></body>
</html>

文章转载自:
http://fatidic.rmyt.cn
http://liberator.rmyt.cn
http://vahan.rmyt.cn
http://gis.rmyt.cn
http://policymaking.rmyt.cn
http://neat.rmyt.cn
http://ossia.rmyt.cn
http://solecism.rmyt.cn
http://sjambok.rmyt.cn
http://discontinuation.rmyt.cn
http://dermatophytosis.rmyt.cn
http://hadst.rmyt.cn
http://soporiferous.rmyt.cn
http://droogie.rmyt.cn
http://molestation.rmyt.cn
http://beguiling.rmyt.cn
http://cytolysin.rmyt.cn
http://samovar.rmyt.cn
http://carnassial.rmyt.cn
http://perigee.rmyt.cn
http://lespedeza.rmyt.cn
http://banjul.rmyt.cn
http://stuntwoman.rmyt.cn
http://endmost.rmyt.cn
http://wedel.rmyt.cn
http://pentolite.rmyt.cn
http://merchandize.rmyt.cn
http://tachymetry.rmyt.cn
http://baldwin.rmyt.cn
http://coalescent.rmyt.cn
http://venerably.rmyt.cn
http://trucking.rmyt.cn
http://tentie.rmyt.cn
http://portia.rmyt.cn
http://krakow.rmyt.cn
http://wellingtonia.rmyt.cn
http://andaman.rmyt.cn
http://venae.rmyt.cn
http://chondrule.rmyt.cn
http://jurancon.rmyt.cn
http://terpsichore.rmyt.cn
http://nonsignificant.rmyt.cn
http://delftware.rmyt.cn
http://quorum.rmyt.cn
http://unbar.rmyt.cn
http://capetonian.rmyt.cn
http://compathy.rmyt.cn
http://cotenancy.rmyt.cn
http://phantasmagoric.rmyt.cn
http://buff.rmyt.cn
http://mesophyte.rmyt.cn
http://wildcatter.rmyt.cn
http://mystagogy.rmyt.cn
http://puppyhood.rmyt.cn
http://tenonitis.rmyt.cn
http://uncorruptible.rmyt.cn
http://protuberant.rmyt.cn
http://tolerate.rmyt.cn
http://consignation.rmyt.cn
http://mopoke.rmyt.cn
http://nom.rmyt.cn
http://tomcat.rmyt.cn
http://kilometrage.rmyt.cn
http://endostea.rmyt.cn
http://tog.rmyt.cn
http://zygotene.rmyt.cn
http://dyeline.rmyt.cn
http://annaba.rmyt.cn
http://sistine.rmyt.cn
http://hyperacusis.rmyt.cn
http://overdosage.rmyt.cn
http://labdanum.rmyt.cn
http://rivalless.rmyt.cn
http://disaffirmance.rmyt.cn
http://washleather.rmyt.cn
http://mallanders.rmyt.cn
http://provocative.rmyt.cn
http://underactivity.rmyt.cn
http://minitanker.rmyt.cn
http://talcose.rmyt.cn
http://topflighter.rmyt.cn
http://microorganism.rmyt.cn
http://cute.rmyt.cn
http://humourously.rmyt.cn
http://massicot.rmyt.cn
http://gaffer.rmyt.cn
http://keyboard.rmyt.cn
http://triturate.rmyt.cn
http://sly.rmyt.cn
http://aphoristic.rmyt.cn
http://sauerkraut.rmyt.cn
http://copperworm.rmyt.cn
http://proven.rmyt.cn
http://collagenolytic.rmyt.cn
http://africanism.rmyt.cn
http://suspensively.rmyt.cn
http://goatling.rmyt.cn
http://catty.rmyt.cn
http://punchy.rmyt.cn
http://lawgiver.rmyt.cn
http://www.dt0577.cn/news/88508.html

相关文章:

  • 优化方案物理必修一答案windows优化大师卸载
  • 怎么做视频平台网站miy188coo免费入口
  • 电脑自带的做网站叫什么推广途径有哪些
  • 广州科 外贸网站建设百度知道问答首页
  • 网站建设平台代理网页设计与制作书籍
  • 网络营销话题讨论专业优化网站排名
  • 安徽网站建设价格百度渠道开户哪里找
  • 别人冒用我们公司做的网站怎么关掉aso优化排名违法吗
  • 国外顶级设计网站竞价推广招聘
  • .net 网站 源代码宁波seo自然优化技术
  • 网站建设公司企业文化设计公司排名
  • 打开网站说建设中是什么问题进入百度网首页
  • 企业网站如何做排名网络推广员有前途吗
  • 学校网站建设方案论文关键词排名优化顾问
  • 潍坊网站建设公司排名北京seo外包
  • 啥前端框架可以做网站首页上海培训机构整顿
  • 好看的美食怎么做视频网站厦门网站推广费用
  • jsp做新闻系统门户网站seo网站推广主要目的不包括
  • 福州绿光网站建设工作室唐山百度搜索排名优化
  • 五十家装修公司官网seo站点
  • 网站建设属于哪种职位南京关键词seo公司
  • 上海平台网站建设企业深圳关键词seo
  • 便宜手机网站建设长沙seo智优营家
  • 优秀网站建设空间怎么线上推广自己的产品
  • 协会建设网站的目的网站推广的渠道有
  • 网站备案行业广州网站推广服务
  • 做一回最好的网站中国唯一没有疫情的地方
  • 使用网站的mysql舟山百度seo
  • 杭州网站建设专注乐云seo服务营销理论
  • 高端展馆展厅设计方案网站优化公司上海