zoukankan      html  css  js  c++  java
  • 每日博客

    时间:大概三个小时

    代码:大概100行

    博客:1

    知识点:php

    <?php
    session_start();
    try
    {$pdo = new PDO("mysql:host=localhost;dbname=test;", "root", "fx30001225");}
    catch (PDOException $e) {die("数据库连接失败" . $e->getMessage());}
    $pdo->query("SET NAMES 'UTF8'");
    switch ($_GET['action'])
    {
        case 'login':
        {
            $name = $_POST['name'];
            $sex = $_POST['sex'];
            $str = "";
            if ($sex == '女') $str = $name . ' 小姐';
            else $str = $name . ' 先生';
            $_SESSION['msg'] = $str;
            $sql = "SELECT *FROM stu WHERE NAME ='{$name}'";
            $stmt = $pdo->query($sql);
            if($stmt->rowCount()> 0 )
            {
                $stu = $stmt->fetch(PDO::FETCH_ASSOC);
                $_SESSION['id']=$stu['id'];
                echo "<script>window.location='ex02c.php' </script>";
            }
            else {echo "<script>window.location='ex02b.php'</script>";}
            break;
        }
        case 'add':
            {
                $name = $_POST['name'];
                $sex = $_POST['sex'];
                $hobby = $_POST['hobby'];
                $address = $_POST['address'];
                $age = $_POST['age'];
                $_SESSION['name']=$name;
                $sql = "INSERT INTO stu VALUES (NULL ,'{$sex}','{$name}','{$age}','{$address}','{$hobby}')";
                $rw = $pdo->exec($sql);
                if ($rw > 0)
                {
                    echo "<script> alert('您的资料保存成功');
                                   window.location='ex02c.php'; //跳转
                         </script>";
                }
                else
                    {
                        echo "<script> alert('增加失败');
                                   window.history.back(); 
                              </script>";
                    }
            }
            break;
        case 'del':
        {
            $id = $_GET['id'];
            $sql = "DELETE FROM stu WHERE id='{$id}'";
            $rw = $pdo->exec($sql);
            if ($rw > 0)
            {
                echo "<script> alert('数据删除成功!');
                                   window.location='ex02b.php'; 
                        </script>";
            }
            else {
                echo "<script> alert('数据删除失败!');
                                   window.history.back(); 
                        </script>";
            }
            break;
        }
        case edit:
        {
            $id = $_POST['id'];
            $name = $_POST['name'];
            $sex = $_POST['sex'];
            $hobby = $_POST['hobby'];
            $address = $_POST['address'];
            $age = $_POST['age'];
            $sql = "UPDATE stu SET name='{$name}',sex='{$sex}',age='{$age}',address='{$address}',hobby='{$hobby}' WHERE id='{$id}'";
            $rw = $pdo->exec($sql);
            if ($rw > 0)
            {echo "<script>alert('修改成功');window.location='ex01b.php'</script>";}
            else {echo "<script>alert('修改失败');window.history.back()</script>";}
            break;
        }
    }
  • 相关阅读:
    BestCoder 1st Anniversary ($) 1002.Hidden String
    Oracle 复制随意表一行的SQL语句(測试Ok)
    华为招聘机试整理15:约瑟夫环
    302跳转
    CCNP路由实验之十 组播(多播)
    How to test Heat (by quqi99)
    用关联容器实现文本替换单词
    【C语言】04-函数
    WAS集群系列(5):集群搭建:步骤3:安装IHS软件
    [Apple开发者帐户帮助]七、注册设备(2)注册多个设备
  • 原文地址:https://www.cnblogs.com/hfy717/p/14507872.html
Copyright © 2011-2022 走看看