php post介面,註冊功能

2022-03-06 04:42:26 字數 1554 閱讀 3533

功能描述:僅輸入手機號和密碼,實現註冊功能。手機號有簡單的驗證,不可重複輸入,否則會報500錯誤。

在使用 restclient 進行post測試時,如果你把引數放在 【headers】區塊了,那麼,插入的資料值是空的,可以看下圖:

我把傳回的引數值 tel 和 pwd 的值和content-type放在一起了,這是不對的,因為【payload】中的引數為空,因此在檢視資料庫時,發現插入了一條引數為空的資料:

在使用 restclient 進行post測試時,【headers】區塊僅僅是新增 content-type,而【payload】區塊才是新增引數的地方:

這時也能查到資料:

同查詢功能一樣,這個介面也是分5步走:

連線伺服器,防止中文亂碼

選擇資料庫

執行sql語句,設定post的引數,判斷手機號是否重複

根據插入的資料返回值,判斷是否新增成功

關閉伺服器

下面是**:

<?php 

//post 介面

//1、連線伺服器

$link = mysql_connect("localhost","root","root") or die ("連線伺服器失敗".mysql_error());

//防止中文亂碼

mysql_query("set names utf8");

//2、選擇資料庫

mysql_select_db("test",$link) or die("選擇資料庫失敗".mysql_error());

//3、執行sql 語句,插入資料庫中的資料,也就是引數

$tel = $_post["tel"];

$pwd = $_post["pwd"];

//判斷手機號是否重複

$insert = "select * from t_user where user_phone = '$tel'";

$result =mysql_query($insert);

//mysql_num_rows 從查詢到的結果集中返回與條件匹配的行數

$rows =mysql_num_rows($result);

if($rows == 1)

else

else

}//5、關閉伺服器

mysql_close($link);

?>

post介面在本地進行測試的,因此它的介面為:http://localhost/registered.php。

registered.php也就是上面的這段**。

php post介面,登入功能

註冊使用查詢語句是為了判斷註冊用的字段值是否重複 註冊失敗 註冊成功 登入使用查詢語句是為了查詢表中是否有那個欄位的值 登入成功 登入失敗 註冊時,使用 row mysql num rows result 如果 row 1,手機號存在,註冊失敗 登入時,使用 row mysql num rows r...

php post請求http介面

這裡用的是curl方式,所以要先保證curl函式庫開啟 在php.ini 檔案裡 extension php curl.dll前面的 分號去掉 上 模擬post進行url請求 param string url param array post data function request post u...

php post 為空 php實現簡單聊天功能

每日17點準時技術乾貨分享 php實現簡單聊天功能 1 建立聊天訊息表,其表的字段有訊息內容,傳送時間和傳送者的名稱 sql create table guanhui message id int 10 not null auto increment comment 訊息id content var...