zoukankan      html  css  js  c++  java
  • 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);
    ?>

  • 相关阅读:
    手机体验细节小动画
    第一次用AngularJS
    鼠标离开方向检测
    回忆之placeholder
    回忆之日历
    大数据学习
    shell 二
    十三:变量、函数、存储过程、循环控制结构
    十二:事务与视图
    十一:约束
  • 原文地址:https://www.cnblogs.com/jiangger/p/6439848.html
Copyright © 2011-2022 走看看