首页 新闻 赞助 找找看

php实现静态页面与数据库之间的运行,该如何做

0
[已解决问题] 解决于 2016-12-16 10:17

现在所学的php如何调动静态页面与数据库之间的运行

微微一笑回眸一生的主页 微微一笑回眸一生 | 初学一级 | 园豆:2
提问于:2016-12-15 09:53
< >
分享
最佳答案
0
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link rel="stylesheet" type="text/css" href="styles/common.css"/>
</head>

<body>
<?php

if
(isset($_POST['button'])){
    $username=$_POST['username'];//得到用户输入的用户名
    $password=$_POST['password'];//密码
     mysql_connect('127.0.0.1:3306','root','')or die(mysql_error());//连接数据库
    mysql_select_db('mvc_study');//选择数据库
    mysql_query('set names utf8');
    
    $sql = "select * from users
     where username = '$username' and password='$password'";
     $rs=mysql_query($sql);
     if(mysql_num_rows($rs)==1){//如果数据库的行数为1则成功否则失败
        echo '登陆成功';
        }else{
            echo '登录失败';
             }
    }
?>
<form id="form1" name="form1" method="post" action="">
  <table width="254" border="1" align="center">
    <tr>
      <th colspan="2" scope="col">用户登录</th>
    </tr>
    <tr>
      <td width="70">用户名</td>
      <td width="168"><label for="username"></label>
      <input type="text" name="username" id="username" /></td>
    </tr>
    <tr>
      <td>密码</td>
      <td><input type="password" name="password" id="password" /></td>
    </tr>
    <tr>
      <td colspan="2" align="center"><label for="password">
        <input type="submit" name="button" id="button" value="提交" />
      </label></td>
    </tr>
  </table>
</form>
</body>
</html>

这是我写的一个PHP连接数据库实现登录的小例子,不知能能不能解决你的疑惑。

奖励园豆:5
kang_ya_ping | 菜鸟二级 |园豆:243 | 2016-12-15 20:11

完美解决,十分感谢啊

微微一笑回眸一生 | 园豆:2 (初学一级) | 2016-12-16 10:17
其他回答(1)
0

php 是静态页面与数据库的中介,你可以用php从数据库取数据向静态页面写数据,或者静态页面通过ajax请求php服务读取数据库数据。

刘阳|lyang|yangakw | 园豆:212 (菜鸟二级) | 2016-12-15 12:01

ok,谢谢亲

清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册