zoukankan      html  css  js  c++  java
  • 错题集-php

    插入======

        <?php
        // 1.接收前端的数据
        $a = @$_GET["aa"];
        $b = @$_GET["bb"];
        $c = @$_GET["cc"];
    
        
        // 2.连接mysql
        $link = @mysql_connect("localhost:3306","root","1002128447");
        if(!$link){
            echo 0;
        }
        // 3.选择数据库
        $db = @mysql_select_db("test1903");
        if(!$db){
            echo 1;
        }
        // 4.设置字符集
        $utf = @mysql_query("set names utf8");
        if(!$utf){
            echo 2;
        }
        // 5.插入数据
        $insert = mysql_query('INSERT project (bt,cont,msg) VALUES("'.$a.'","'.$b.'","'.$c.'")');
        if($insert){
            // 6.插入成功,返回所有数据
            echo select();
        }else{
            echo 3;
        }
    
    
        // 专门用来请求所有数据的函数
        function select(){
            $q = mysql_query('SELECT * FROM project');
            if($q){
                $str = "";
                while(true){
                    $arr = mysql_fetch_assoc($q);
                    if(!$arr){
                        break;
                    }
                    
                    $str = $str.json_encode($arr).",";
                }
                return "[".substr($str,0,-1)."]";
            }else{
                return 4;
            }
        }
    ?>
    

    更新

        <?php
        // 1.接收前端的数据
        $a = @$_GET["aa"];
        $b = @$_GET["bb"];
        $c = @$_GET["cc"];
        $id = @$_GET["id"];
    
    
        // 2.连接mysql
        $link = @mysql_connect("localhost:3306","root","10021284471002128447");
        if(!$link){
            echo 0;
        }
        // 3.选择数据库
        $db = @mysql_select_db("test1903");
        if(!$db){
            echo 1;
        }
        // 4.设置字符集
        $utf = @mysql_query("set names utf8");
        if(!$utf){
            echo 2;
        }
    
        // 5.更新数据
        $update = mysql_query('UPDATE project SET bt="'.$a.'",cont="'.$b.'",msg="'.$c.'" WHERE id='.$id);
        if($update){
            echo 6;//echo select()
        }else{
            echo 3;
        }
     // 专门用来请求所有数据的函数
    // function select(){
    //     $q = mysql_query('SELECT * FROM project');
    //     if($q){
    //         $str = "";
    //         while(true){
    //             $arr = mysql_fetch_assoc($q);
    //             if(!$arr){
    //                 break;
    //             }
                
    //             $str = $str.json_encode($arr).",";
    //         }
    //         return "[".substr($str,0,-1)."]";
    //     }else{
    //         return 4;
    //     }
    // }
    
    
    ?>
    
    

    选择

    <?php
    
       // 1.连接mysql
       $link = @mysql_connect("localhost:3306","root","1002128447");
       if(!$link){
           echo 0;
       }
       // 2.选择数据库
       $db = @mysql_select_db("test1903");
       if(!$db){
           echo 1;
       }
       // 3.设置字符集
       $utf = @mysql_query("set names utf8");
       if(!$utf){
           echo 2;
       }
    
       
       echo select();
    
    
       // 专门用来请求所有数据的函数
       function select(){
           $q = mysql_query('SELECT * FROM project');
           if($q){
               $str = "";
               while(true){
                   $arr = mysql_fetch_assoc($q);
                   if(!$arr){
                       break;
                   }
                   
                   $str = $str.json_encode($arr).",";
               }
               return "[".substr($str,0,-1)."]";
           }else{
               return 4;
           }
       }
    
    ?>
    
  • 相关阅读:
    RxJava【创建】操作符 create just from defer timer interval MD
    RxJava【过滤】操作符 filter distinct throttle take skip first MD
    jQuery效果之封装模拟placeholder效果,让低版本浏览器也支持
    jQuery效果之jQuery实现图片的依次加载图片
    JS实现缓动效果-让div运动起来
    apache配置-html碎片shtml格式
    wamp本地可以访问,远程无法访问,报错:client denied by server configuration
    webstorm编辑器相关
    wamp安装运行时出现服务未启动
    phpcms导航菜单的写法
  • 原文地址:https://www.cnblogs.com/sansancn/p/10922852.html
Copyright © 2011-2022 走看看