暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

PHP & MySQL 总结

阿帆fan 2021-05-07
167

zhuce.php

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>注册</title>
    </head>
    <body>
    <form action="zhuce_in.php" method="post" onsubmit="return tijiao(this)">
    用户名:<input type="text" name="username" value="">*
    <br>
    密码:<input type="password" name="password" value="">*
    <br>
    性别:<input type="radio" name="sex" value="男">男
    <input type="radio" name="sex" value="女">女
    <br>
    <br>
    爱好:<br>
    <input type="checkbox" name="hobby[]" value="游泳">游泳<br>
    <input type="checkbox" name="hobby[]" value="读书">读书<br>
    <input type="checkbox" name="hobby[]" value="健身">健身<br>
    <input type="checkbox" name="hobby[]" value="timi">timi<br>
    城市:<br>
    <select name="city">
    <option selected disabled>请选择</option>
    <option>烟台</option>
    <option>菏泽</option>
    <option>淄博</option>
    <option>潍坊</option>
    <option>济宁</option>
    <option>枣庄</option>
    <option>滨州</option>
    </select>
    <br><br>
    <input type="submit" value="注册">
    </form>
    带*必须填写!
    <script>
    function tijiao(form){
    if(form.username.value=='')
    {
    alert('请输入用户名!');
    return false;
    }
    if(form.password.value=='')
    {
    alert('请输入密码!');
    return false;
    }
    }
    </script>
    </body>
    </html>
    复制




    zhuce_in.php

      <!doctype html>
      <html>
      <head>
      <meta charset="utf-8">
      <title>注册页面</title>
      </head>


      <body>
      <?php
      $name=$_POST['username'];
      $password=$_POST['password'];
      $sex=$_POST['sex'];
      $hobby=$_POST['hobby'];
      $city=$_POST['city'];
      $hobbies='';
      foreach($hobby as $a)


      $link=mysqli_connect("localhost","root","","stu_info");
      mysqli_set_charset($link,'utf8');
      $sql = "insert into user (id,name,password,sex,hobby,city)values(null,'$name','$password','$sex','$hobbies','$city')";
      mysqli_query($link,$sql);
      header('location:zhuce.php');
      ?>
      </table>
      </body>
      </html>
      复制




      list.php

        <!doctype html>
        <html>
        <head>
        <meta charset="utf-8">
        <title>用户信息打印页面</title>
        </head>


        <body>
        <?php
        $link=mysqli_connect("localhost","root","","stu_info");
        mysqli_set_charset($link,'utf8');
        $rel = mysqli_query($link,'select * from user');
        ?>
        <h1 align=center>用户信息</h1>
        <a href="./zhuce.php">添加信息</a>
        <table align=center border=1px cellspacing=0 cellpadding=0>
        <tr>
        <th>id</th>
        <th>name</th>
        <th>password</th>
        <th>sex</th>
        <th>hobby</th>
        <th>city</th>
        <th>change</th>
        </tr>
        <?php
        while($result = mysqli_fetch_array($rel) )
        {
        echo '<tr><td>'.$result['0'].'</td>';
        echo '<td>'.$result['1'].'</td>';
        echo '<td>'.$result['2'].'</td>';
        echo '<td>'.$result['3'].'</td>';
        echo '<td>'.$result['4'].'</td>';
        echo '<td>'.$result['5'].'</td>';
        echo "<td> <a href='delete.php?id=$result[0] '>";
        echo '删除';
        echo '</a>';
              echo '&nbsp'."<a href='up.php?id=$result[0] '>"."修改"."</a>";
        echo ' </td>';
        echo '</tr>';
        }
        ?>
        </table>
        </body>
        </html>
        复制




        delete.php

          <?php
          $id = $_GET['id'];
          $link = mysqli_connect('localhost','root','','stu_info');
          mysqli_set_charset($link,'utf8');
          $sql = "delete from user where id=$id";
          $a = mysqli_query($link,$sql);
          header('location:list.php');
          ?>
          复制



          up.php

            <!DOCTYPE html>
            <html lang="en">
            <head>
            <meta charset="UTF-8">
            <title>Document</title>
            </head>
            <body>
            <?php
            $id = $_GET['id'];
            $link = mysqli_connect('localhost','root','','stu_info');
            mysqli_set_charset($link,'utf8');
            $sql = "select * from user where id=$id";
            $res = mysqli_query($link,$sql);
            $rows = mysqli_fetch_array($res);
            echo '序号:'.$rows[0];
            ?>
            <form action="update.php" method="post">
            <input type="hidden" name="id" value="<?php echo $rows[0]; ?>"><br>
            姓名:<input type="text" name="name" value="<?php echo $rows[1]; ?>"><br>
            密码:<input type="text" name="password" value="<?php echo $rows[2]; ?>"><br>
            <?if($rows[3] == '男'){?>
            <input type="radio" name="sex" value="男" checked="checked">
            <input type="radio" name="sex" value="女"><br>
            <?} else { ?>
            <input type="radio" name="sex" value="男">
            <input type="radio" name="sex" value="女" checked="checked"><br>
            <?}?>
            爱好:<input type="text" name="hobby" value="<?php echo $rows[4]; ?>"><br>
            城市:<input type="text" name="city" value="<?=$rows[5] ?>"><br>
            <input type="submit" value="修改" >
            </form>
            </body>
            </html>
            复制




            update.php

              <?php
              $id = $_POST['id'];
              $name = $_POST['name'];
              $password = $_POST['password'];
              $sex = $_POST['sex'];
              $hobby = $_POST['hobby'];
              $city = $_POST['city'];
              $link = mysqli_connect('localhost','root','','stu_info');
              mysqli_set_charset($link,'utf8');
              $sql = "update user set name = '$name',password = '$password',sex = '$sex',hobby = '$hobby',city = '$city' where id = $id";
              mysqli_query($link,$sql);
              header('location:list.php');
              ?>
              复制



              @阿帆fan


              点这里给我留言



              点这里进入阿帆的论坛


              相关推荐:


              在网页中修改MySQL的数据

              怎样把MySQL里的数据库打印到网页中?

              把网页表单中的数据放到MySQL

              PHP连接数据库(一)

              MySQL数据库命令表


              文章转载自阿帆fan,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

              评论