這個技術(shù)稍微綜合了PHP的基礎(chǔ)知識,
成都創(chuàng)新互聯(lián)公司主營金東網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,成都App定制開發(fā),金東h5小程序制作搭建,金東網(wǎng)站營銷推廣歡迎金東等地區(qū)企業(yè)咨詢
給你一個思路,
(1) 先將textarea 文本中的信息 傳入 php的 $_POST['content'], content 是textarea的屬性名稱,
(2) 傳過來的值是通過數(shù)組的形式進行保存的 ,其中PHP有一個函數(shù)是可以將數(shù)組轉(zhuǎn)換成字符串形式,
引用那個函數(shù)后,通過var_dump()打印出你的轉(zhuǎn)換數(shù)據(jù),看是否是字符串
在這里需要提醒你一下,因為你是每一行作為一句話 通過逗號分隔出來的 ,那么 在轉(zhuǎn)換成數(shù)組的時候,
將每一行數(shù)據(jù) 用 | 隔開,例如:
數(shù)據(jù)1 , 數(shù)據(jù)11, 數(shù)據(jù)111 | 數(shù)據(jù)2, 數(shù)據(jù)22, 數(shù)據(jù)222| 數(shù)據(jù)3 , 數(shù)據(jù)33, 數(shù)據(jù)333 | 數(shù)據(jù)4, 數(shù)據(jù)44, 數(shù)據(jù)444 |
這就是一個轉(zhuǎn)換成字符串的格式了,
(3) 通過轉(zhuǎn)換成字符串后,php中還有一個函數(shù)就是將字符串轉(zhuǎn)換成 數(shù)組的函數(shù),轉(zhuǎn)換結(jié)果應(yīng)該出來的數(shù)據(jù)格式是:
array=
array(0)=array{
'數(shù)據(jù)1,數(shù)據(jù)11,數(shù)據(jù)111'
},
array(1)=array{
'數(shù)據(jù)2,數(shù)據(jù)22,數(shù)據(jù)222'
}....
(4)以上的數(shù)據(jù)都是索引數(shù)組的二維數(shù)組,將二維數(shù)組用foreach()去循環(huán)打印出來,那么久可以得到每一個 所以數(shù)組下的 數(shù)據(jù)了,這些數(shù)據(jù)
就是你要保存到數(shù)據(jù)的數(shù)據(jù),在按照(1)和(2)的方式進行操作,最后就可以把textarea的數(shù)據(jù)保存到數(shù)據(jù)庫中咯。
思路就是這樣的 ,希望你能自己動手,把這個程序解決,這個程序在實際開發(fā)中運用的很廣泛,最好自己把它掌握了.....
你可以用 PHP 的 MySQLi 或 PDO 庫來實現(xiàn)。
首先,你需要使用這些庫中的函數(shù)連接數(shù)據(jù)庫,然后把表單中的字段值插入到相應(yīng)的數(shù)據(jù)表中。
例如,如果你使用 MySQLi,你可以這樣寫:
$conn = mysqli_connect("hostname", "username", "password", "database_name");
$rwid = $_POST['rwid'];
$rwdj = $_POST['rwdj'];
$rwzb = $_POST['rwzb'];
$sql1 = "INSERT INTO table_a (s) VALUES ('$rwid')";
mysqli_query($conn, $sql1);
$sql2 = "INSERT INTO table_b (d) VALUES ('$rwdj')";
mysqli_query($conn, $sql2);
$sql3 = "INSERT INTO table_c (f) VALUES ('$rwzb')";
mysqli_query($conn, $sql3);
如果你使用 PDO,你可以這樣寫:
$conn = new PDO("mysql:host=hostname;dbname=database_name", "username", "password");
$rwid = $_POST['rwid'];
$rwdj = $_POST['rwdj'];
$rwzb = $_POST['rwzb'];
$stmt1 = $conn-prepare("INSERT INTO table_a (s) VALUES (:s)");
$stmt1-bindParam(':s', $rwid);
$stmt1-execute();
$stmt2 = $conn-prepare("INSERT INTO table_b (d) VALUES (:d)");
$stmt2-bindParam(':d', $rwdj);
$stmt2-execute();
$stmt3 = $conn-prepare("INSERT INTO table_c (f) VALUES (:f)");
$stmt3-bindParam(':f', $rwzb);
$stmt3-execute();
希望這個答案對你有幫助。
首先你要建立一個表,例如是注冊的用戶表user
,里面的結(jié)構(gòu)有字段
id,
name,nickname,email等。
然后在你的表單處form
action="a.php"
method="post"
name="regform"(如果有圖片上傳,還要加上enctype="multipart/form-data")
,那么點擊表單提交按紐后,此表單將會交給處理頁a.php來作處理。
如果簡單點,你就直接可以將表單傳遞過來的數(shù)據(jù)$_POST,直接用sql插入語句,insert
into來插入到數(shù)據(jù)庫,表user中。例如insert
into
user
set
name='".$_POST['name']."'.............................
php數(shù)據(jù)庫操作主要分為5個步驟:1連接MYSQL
2連接到你的數(shù)據(jù)庫
3寫SQL語句
4運行sql語句
5關(guān)閉數(shù)據(jù)庫
//第一步
$con
=
mysql_connect("localhost","root","123456789");
//第二步
mysql_select_db('rankingme',$conn);
//第三步
$sql="insert
into
lili
(name,sex,et,hobby,photo,tel,address,content,time)
values
($name,$sex,$et,$hobby,$photo,$tel,$address,$content,$time)"
//第四步
mysql_query($sql);
//第五步
mysql_close($con);
1:首先要使用PHP的超全局變量 $_GET 和 $_POST 用于收集表單數(shù)據(jù)(form-data)
2:然后使用INSERT INTO 語句用于向數(shù)據(jù)庫表中插入新記錄。
具體示例:
(1)首先創(chuàng)建了一個名為 "Persons" 的表,有三個列:"Firstname", "Lastname" 以及 "Age"。
?php
$con?=?mysql_connect("localhost","peter","abc123");
if?(!$con)
{
die('Could?not?connect:?'?.?mysql_error());
}
mysql_select_db("my_db",?$con);
mysql_query("INSERT?INTO?Persons?(FirstName,?LastName,?Age)?
VALUES?('Peter',?'Griffin',?'35')");
mysql_query("INSERT?INTO?Persons?(FirstName,?LastName,?Age)?
VALUES?('Glenn',?'Quagmire',?'33')");
mysql_close($con);
?
(2)其次創(chuàng)建一個 HTML 表單,這個表單可把新記錄插入 "Persons" 表。
html
body
form?action="insert.php"?method="post"
Firstname:?input?type="text"?name="firstname"?/
Lastname:?input?type="text"?name="lastname"?/
Age:?input?type="text"?name="age"?/
input?type="submit"?/
/form
/body
/html
(3)接著當(dāng)用戶點擊上例中 HTML 表單中的提交按鈕時,表單數(shù)據(jù)被發(fā)送到 "insert.php"。"insert.php" 文件連接數(shù)據(jù)庫,并通過
$_POST 變量從表單取回值。然后,mysql_query() 函數(shù)執(zhí)行 INSERT INTO 語句,一條新的記錄會添加到數(shù)據(jù)庫表中。
?php
$con?=?mysql_connect("localhost","peter","abc123");
if?(!$con)
{
die('Could?not?connect:?'?.?mysql_error());
}
mysql_select_db("my_db",?$con);
$sql="INSERT?INTO?Persons?(FirstName,?LastName,?Age)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
if?(!mysql_query($sql,$con))
{
die('Error:?'?.?mysql_error());
}
echo?"1?record?added";
mysql_close($con)
?
一、php配置MySQL
1、將php安裝目錄下的php_mysql.dll和MySQL安裝目錄下的libmysql.dll文件拷貝至c:/windows/system32中;
2、配置php.ini
extension=php_gd2.dll
extension=php_mbstring.dll
extension=php_mysql.dll
extension=php_mysqli.dll
把上面四個。dll的最前面的;去掉
二、php表單提交至數(shù)據(jù)庫的實現(xiàn)過程
1、login.php頁面
SPAN style="FONT-SIZE: 14px"html
FORM method=post action=add.php
Name: INPUT name=usernameBR
Email: INPUT name=emailBR
INPUT value=提交 type=submit name=submit
/FORM
/SPAN
2、add.php頁面
SPAN style="FONT-SIZE: 14px"?php
include("conn.php");
?
?php
if(isset($_POST["submit"]))
{
$sql = "insert into users(username, email) values('$_POST[username]', '$_POST[email]')";
mysqli_query($conn, $sql);
echo "添加成功";
}
?/SPAN
3、conn.php頁面
SPAN style="FONT-SIZE: 14px"?php
$conn = new mysqli("localhost", "root", "159357");
$conn-select_db("db_test");
//mysql_query("set name 'gb2312'");
$conn-set_charset("utf8");
?/SPAN
網(wǎng)站題目:php表單數(shù)據(jù)來自數(shù)據(jù)庫 php表單顯示數(shù)據(jù)庫內(nèi)容
網(wǎng)址分享:http://chinadenli.net/article28/dodeocp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作、域名注冊、外貿(mào)建站、ChatGPT、響應(yīng)式網(wǎng)站、微信公眾號
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)