php向mysql寫入資料

來源:互聯網
上載者:User

標籤:names   表單   bsp   pos   mail   query   建立   cal   img   

利用PHP的post方式將擷取到的資料寫入mysql資料庫中。

 

首先建立一個用於接收使用者資料的表單頁面 denglu.html 

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<form action="./xinxi.php" method=‘POST‘>
<p>使用者名稱:<input type="text" name="username" value="請輸入手機號碼"></p>
<p>性 別:<input type="radio" name="sex" value="man" >先生<input type="radio" name=‘sex‘ value="woman">女士</p>
<p>出生年月:<input type="text" name="year" value="1990">年<input type="text" name="yue" value="01">月<input type="text" name="ri" value="01">日</p>
<p>郵 箱:<input type="text" name="email"></p>
<p>密 碼:<input type="password" name="password"></p>
<p>確認密碼:<input type="password" name="password"></p>
<p><input type="submit" value="Login"></p>
</form>

接著建立一個用於載入 denglu.html 的Login.php

<?php

include ‘./denglu.html‘;

 

建立一個能接收使用者填寫資料的,並且能使用語句操作mysql的 xinxi.php,該php代碼是用於denglu.html中action指定的處理表單資料的伺服器。

 1 <?php 4 $birth =$_POST[‘year‘].$_POST[‘yue‘].$_POST[‘ri‘];  5 $pass = md5($_POST[‘password‘]);    6  7 $flag=mysql_connect(‘localhost‘,‘root‘,‘******‘);    8 $f=mysql_query(‘use  test1‘);                 9 $f=mysql_query(‘set names utf8‘);     
       10 $conn="insert into yonghu(username,sex,birth,email,password) values(‘{$_POST[‘username‘]}‘,‘{$_POST[‘sex‘]}‘,‘{$birth}‘,‘{$_POST[‘email‘]}‘,‘{$pass}‘);";11 if($_POST){12 $username = isset($_POST[‘username‘]) ? $_POST[‘username‘] :‘‘;13 if(isset($username)){14 mysql_query($conn);15 echo "insert into yonghu(username,sex,birth,email,password) values(‘{$_POST[‘username‘]}‘,‘{$_POST[‘sex‘]}‘,‘{$birth}‘,‘{$_POST[‘email‘]}‘,‘{$pass}‘);";16 echo "<hr />傳入資料成功!";17 die;21 }22 }

 

 

 

 

效果

 

php向mysql寫入資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.