zoukankan      html  css  js  c++  java
  • 四、php基础

    php里衔接变量和字符串用【.】

      echo $name."<br>";
      echo $name.$age;

    php连接数据库:
      1、建立链接
      2、数据操作
      3、结果处理

    mysql_connect(); php和mysql连接,apache解析

    1、在html表单中post、get传输数据;
       <form action="getregister.php" method="post"> //html代码
    2、建立php文件,如下:php语句可以写在<body>标签中
      <?php
      //a、创建与数据库连接
      $con=mysql_connect("localhost:13306","root","123456");
      if($con){
      echo "sucess<br>";
      }else{
      echo "fail".mysql_error();
      }


      //b、选择数据库和编码方式
      mysql_select_db("stu");
      mysql_query("set names utf8");


      //c、操作语句:这里是查询语句
      $query="select * from stu" ;
      $rest=mysql_query($query);
      echo "<table border='1'>";
      while($row=mysql_fetch_row($rest)){
       echo "<tr>";
      echo "<td>$row[0]</td><td>$row[1]</td><td>$row[2]</td>";
      echo "</tr>";
      }
      echo "</table>";

    ?>


























    <?php
    /*$uname=$_GET['username'];
    $umobile=$_GET['tel'];
    $uid=$_GET['code'];*/

    /*$uname=$_POST['username'];
    $umobile=$_POST['tel'];
    $uid=$_POST['code'];*/



    //插入
    $con=mysql_connect("localhost:13306","root","123456");
    if($con){
    echo "sucess<br>";
    }else{
    echo "fail".mysql_error();//
    }
    mysql_select_db("stu");
    mysql_query("set names utf8");


    /*$sql="insert into stu values('$uid','$uname','$umobile')";
    $res=mysql_query($sql);
    if($res){
    echo "sucess01";
    }else{
    echo "fail01".mysql_error();
    }*/



    //查询语句
    $query="select * from stu" ;
    $rest=mysql_query($query);
    echo "<table border='1'>";
    while($row=mysql_fetch_row($rest)){
    echo "<tr>";
    echo "<td>$row[0]</td><td>$row[1]</td><td>$row[2]</td>";
    echo "</tr>";
    }
    echo "</table>";

    ?>


  • 相关阅读:
    球面均分算法研究记录
    Vue组件继承实践(设计对话框组件继承)
    laravel--设置不需要csrfToken校验的接口
    ajax--表单带file数据提交报错Uncaught TypeError: Illegal invocation
    前端插件--fastclick解决点透问题
    ES6--反引号的使用
    JQuery--extend的使用
    laravel--laravel的重定向类Redirector
    laravel--request类获取传值
    JQuery--计算元素的宽度
  • 原文地址:https://www.cnblogs.com/ceshixuexi/p/7241895.html
Copyright © 2011-2022 走看看