表單如何與php交互數(shù)據(jù) php表單提交到數(shù)據(jù)庫實例

html如何輸出php的json,提交表單和php交互輸出json

form?method="post"?action="json.php"

成都創(chuàng)新互聯(lián)公司是一家專業(yè)提供西夏企業(yè)網(wǎng)站建設,專注與網(wǎng)站建設、成都網(wǎng)站設計、H5建站、小程序制作等業(yè)務。10年已為西夏眾多企業(yè)、政府機構(gòu)等服務。創(chuàng)新互聯(lián)專業(yè)網(wǎng)絡公司優(yōu)惠進行中。

input???type="text"??id="theuser"?name?="user"?/

input?type="button"?id="enter"?value="提交"?/

/form

script?type="text/javascript"

$(document).ready(function(){

$("#enter").click(function(){

var?theuser?=?$("#theuser").val();

if(theuser?==?'')?{

alert("用戶名不能為空");

return?false;

}

$.post('json.php',?{'user':theuser},?function(data){

if(data.user!=""){

$("#look").html(data.user);

}else?{

//?錯誤處理

}

});

});

});

類似吧, 沒大看明白你的要求.

其實 最好在php端輸出json的時候,加上些狀態(tài)字段,例如:

$result?=?array('asd',?'34234');?//?這是你想要的數(shù)據(jù)

if($result){

echo?json_encode(array('code'=1,?'data'=$result));

}else?{

echo?json_encode(array('code'=0,?'data'=null));

}

這樣在前端的時候容易判斷些, 直接根據(jù)code的狀態(tài)判斷請求的結(jié)果.

php與表單的互動怎么弄

行!用ajax可以實現(xiàn)!

這個還好!可以保證php和html在不同頁面

怎么將表單中的數(shù)據(jù)提交到數(shù)據(jù)庫 php

一、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ù) php表單提交到數(shù)據(jù)庫實例
當前網(wǎng)址:http://bm7419.com/article18/dohjggp.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供ChatGPT、面包屑導航、動態(tài)網(wǎng)站、網(wǎng)頁設計公司、小程序開發(fā)、網(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)

h5響應式網(wǎng)站建設