• mysql


    //login.php

    <html>
    <head>
    </head>
    <body>
    <form action="insert.php" method="POST">
    <b>用户名:</b>
    <input type="text" name="sname"> <br><br>
    <b>密码:</b>
    <input type="text" name="password"> <br><br>
    <input type="submit",name="submit",value="登陆">
    <body>
    </html>

    insert.php

    <?php
    $con = mysql_connect("localhost","root","root");
    if(!$con)
    {
    die(mysql_error());
    }
    mysql_select_db("message",$con);
    // var_dump($_POST);die;
    $sql = "insert into Person(Name,Password) VALUES('$_POST[sname]','$_POST[password]')";
    //mysql_query("insert into Person(Name,Password) VALUES('$_POST[sname]','$_POST[password]')");//中文字符不行;

    if(mysql_query($sql,$con))
    {
    echo "success to stored!";
    }

    echo "<table border = '1'>
    <tr>
    <th>Name</th>
    <th>Password</th>
    </tr>";


    //$result = mysql_query("select * from Person order by Password desc");
    // mysql_query("update Person set Name='hulai' where Name ='kk'");
    mysql_query("delete from Person where Name='hulai'");
    $result = mysql_query("select * from Person");
    while($row = mysql_fetch_array($result))
    {
    echo "<tr>"; // <tr>...</tr>行 <th>...</th>列, <td>...<td>列,且字体比th小,要配合table使用,并且在<?PHP里写必须要用echo
    echo "<td>$row[Name]</td>";
    echo "<td>$row[Password]</td>";
    echo "</tr>";

    }

    echo "</table>";
    mysql_close($con);
    ?>

    //connect.php

    <?php
    $con = mysql_connect("localhost","root","root");
    if(!$con)
    {
    die(mysql_error());

    /*try
    {
    $message = "the mysql is not connect";
    throw new Exception($message);
    }
    catch(Exception $e)
    {
    echo $e->getMessage()."<br>";
    } */
    }
    else
    {
    /*mysql_query("CREATE DATABASE infrom",$con);
    mysql_select_db("infrom",$con);//(ID int NOT NULL AUTO_INCREMENT,PRIMARY KEY(ID),Name varchar(12),Age smallint(100),Birth date());
    $sql = "CREATE TABLE Person
    (
    name vachar(20)
    )";
    if(mysql_query($sql,$con))
    {
    echo "ll";
    }*/
    mysql_query("CREATE DATABASE message",$con);
    mysql_select_db("message", $con);
    $sql = "CREATE TABLE Person(ID int NOT NULL AUTO_INCREMENT,PRIMARY KEY(ID), Name varchar(15),Password varchar(6))";
    mysql_query($sql,$con);
    }

    mysql_close($con);
    ?>

  • 相关阅读:
    图片处理
    define 常量的定义和读取
    curl
    stream_get_contents 和file_get_content的区别
    php flock 文件锁
    字符串函数
    php 常量
    debug_backtrace()
    pathlib模块替代os.path
    Python中对 文件 的各种骚操作
  • 原文地址:https://www.cnblogs.com/jiangger/p/6439848.html
Copyright © 2020-2023  润新知