php 簡單的表單接收

來源:互聯網
上載者:User
表單處理-直接在頁面輸出

如何利用表單處理實現直接在頁面輸出的效果。


1、在php中表單的提交是一種十分重要的資料提交方式。比如登入註冊,購物車等都要用到表單提交。


2、下面我們來學習表單處理,將資料在頁面上輸出。首先我們建立一個簡單的表單。

<html>

<head>

<metacharset="utf-8">

<title>表單處理-直接在頁面輸出</title>

</head>

<body>

       <form action=""method="">

       名字:<input type="text" name="fname"><br><br>

       年齡:<input type="text" name="age"><br><br>

       <input type="submit"value="提交">

       </form>

</body>

</html>


3、在form表單中action規定了當提交表單時,向何處發送表單的資料。action="welcome.php"就是規定了資料要提交到welcome.php檔案處理。method是規定提交的方式,我們這裡用的是post提交方式。

action是規定當提交表單時,向何處發送表單資料。

method是規定提交的方式

<form action="welcome.php"method="post">


4、然後給input標籤定義一個name,只有定義了name屬性,後台才能準確的接收到資料。      

名字: <input type="text"name="fname"><br><br>

name:定義名稱。


5、為讓我們提交的資料能夠在頁面輸出,我們進入welcome.php檔案處理我們提交的資料。


6、在welcome.php中使用echo輸出$_POST接收資料。$_POST['fname']、$_POST['age']分別接收名字和年齡的值,fname、age就是在input中name屬性定義的屬性值。


<?php

header('content-type:text/html;charset=utf-8');

       echo '歡迎' . $_POST['fname'] . '<br>';

       echo '你的年齡是' . $_POST['age'] . '歲';


 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.