zoukankan      html  css  js  c++  java
  • 数据库访问小列题

    <select>
    <?php
    $db=new MySQLi("localhost","root","3177389","my test");
    
    !mysqli_connect_error() or die("连接失败!");
    $sql="select*from Nation";
    
    $result=$db->query($sql);
    $attr=$result->fetch_all();
    
    for($i=0;$i<count($attr );$i++)
    {
        list($code,$name)=$attr[$i];
        
        echo "<option value='{$code}'>{$name}</option>";
        
        
    }
    
    ?>
    </select>
    <?php
    //造连接对象
    $db=new MySQLi("localhost","root","3177389","my test");
    //判断是否出错
    !mysqli_connect_error()or die ("连接失败!");
    //写sql语句
    $sql="select *from Info";
    //执行sql语句
    $result=$db->query($sql);
    //处理查询数据并显示
    echo "<table width='100%' border='1' cellpadding='0' cellpadding='0'>";
    
    echo "<tr><td>代号</td><td>姓名</td><td>性别</td><td>民族</td ><td>生日</td></tr>";
    while($row=$result->fetch_row())
    
    {
        $sex=$row[2]?"男":"女";
        
        $name =ShowNation($db,$row [3]);
        
        echo "<tr><td>{$row[0]}</td><td>{$row[1]}</td><td>{$sex}</td><td>{$name}</td ><td>{$row[4]}</td></tr>";
        
        
    }
    echo "</table >";
    
    
    function showNation ($db,$code)
    
    {
        
            $sql = "select Name from Nation where Code='{$code}'";
            $result=$db->query($sql);
            
            
            $jieguo =$result ->fetch_row();
            
            return $jieguo[0];
    }
    ?>
    <form action="0324chili.php" method="post">
    <div>
            用户名:
            <input type="text" name="zw" />
        </div>
        <div>
            密码:
            <input type="text" name="pwd" />
        </div>
        <div>
            <input type="submit" value="登录" />
        </div>
    
    
    
    </form>
    <?php
    
    $uid=$_POST["zw"];
    $pwd=$_POST["pwd"];
    
    $db=new MySQLi("localhost","root","3177389","my test");
    
    !mysqli_connect_error()or die ("连接失败!");
    
    $sql="select count(*) from login where username='{$uid}' and  password='{$pwd}'";
    
    $resul=$db->query($sql);
    $attr=$resul->fetch_row();
    
    if($attr[0] == 1)
    {
        header("location:zhu.php");
    }
    else
    {
        header("location:denglu.php");
    }
  • 相关阅读:
    Linux makefile教程之概述一[转]
    Valid Parentheses
    Letter Combinations of a Phone Number
    机器学习经典分类算法 —— C4.5算法(附python实现代码)
    3Sum Closest
    3Sum
    Integer to Roman
    寒假文献阅读(四)
    Longest Common Prefix
    Roman to Integer
  • 原文地址:https://www.cnblogs.com/crazy-zw/p/5317827.html
Copyright © 2011-2022 走看看