PHP基本语法(二)

一,表单处理
1.post传送数据
phppost.php

<html>
<body>
<head><meta charset="utf-8" />head>
html>
<form action="psppost2.php" method="post">
    <input type="text" name="data">
    <input type="submit">

form>
body>
html>

phppost2.php

<html>
<body>
<head><meta charset="utf-8" />head>
 你输入了".$_POST["data"];

?>
body>
html>

2.get传送数据
phpget.php

<html>
<body>
<head><meta charset="utf-8" />head>
html>
<form action="pspget2.php" method="get">
    <input type="text" name="data">
    <input type="submit">

form>
body>
html>

phpget2.php

<html>
<body>
<head><meta charset="utf-8" />head>
 你输入了".$_GET["data"];

?>
body>
html>

二,连接数据库


/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/4/2 0002
 * Time: 下午 4:11
 */
//连接语句
$con = mysql_connect("localhost:3306","root","******");
if(!$con)
{
    die('Could not connect:'.mysql_error());
}
else{


    //选择数据库dzl
    mysql_select_db("dzl",$con);
    //查找数据库
    $result =  mysql_query("select * from student");
    while($row =  mysql_fetch_array($result))
    {
        echo $row['sname']." ".$row['sid']."
"
; } mysql_close(); } ?>

你可能感兴趣的:(php)