iT邦幫忙

0

PHP + MSSQL 如何輸入品號帶出品名

小弟PHP只摸過粗淺,想請教各位大大如何讀取JS資料給PHP到MSSQL 撈取資料庫資料

1.我想知道PHP 如何讀到 JS欄位的資料
2.如果上面的方法不行,需求是輸入品號自動帶出相關資料

https://ithelp.ithome.com.tw/upload/images/20210510/20117233kVoEz1TCYW.jpg
html 部分

<div class="w20">
 <label class="f5"></label>
 <label class="f2">半成品品號:</label>
<input class="f5" type="text" name="ItemNumber" ID=ItemNumber />
 <input type="button" value="查詢" onclick='GetValue()' />
 </div>
 <p/>
 <div class="w20">
 <label class="f5"></label>
 <label class="f2">半成品品名:</label>
 <input class="f5" type="text" />
 </div>
 <p/>
 <div class="w20">
 <label class="f5"></label>
 <label class="f2">半成品規格:</label>
 <input class="f5" type="text" />
 </div>

script 部分
function GetValue(){
var ItemNumber= document.getElementsByName('ItemNumber');
var ss =;
alert(ss);
}

archer9080 iT邦研究生 4 級 ‧ 2021-05-10 15:39:43 檢舉
ajax方式
(1)html

<div class="w20">
<label class="f5"></label>
<label class="f2">半成品品號:</label>
<input class="f5" type="text" name="ItemNumber" id="ItemNumber" />
<input type="button" value="查詢" onclick='GetValue()' />
</div>
<p/>
<div class="w20">
<label class="f5"></label>
<label class="f2">半成品品名:</label>
<input class="f5" type="text" id="ItemName" />
</div>
<p/>
<div class="w20">
<label class="f5"></label>
<label class="f2">半成品規格:</label>
<input class="f5" type="text" id="ItemSpec" />
</div>

(2)script

function GetValue(){
let ItemNumber= $("#ItemNumber").val();//取值
$.ajax({
url: 'GetValue.php',
type: 'POST',
async: false,
data : {
ItemNumber:ItemNumber
},
dataType:"json",
success: function (data) {
let ItemName = data.ItemName;
let ItemSpec = data.ItemSpec;
$("#ItemName").val(ItemName);//給值
$("#ItemSpec").val(ItemSpec);//給值
}
});
}

(3).php

$ItemNumber = $_POST['ItemNumber'];
//sql 連接,懶了
.
.
.
//假設都能撈到資料
$result = array('ItemName'=>$ItemName, 'ItemSpec'=>$ItemSpec);
echo json_encode($result);

大致應該這樣,細節部分加油
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
0
koro_michael
iT邦新手 2 級 ‧ 2021-05-10 15:03:25

這個範圍太大不知道要怎麼回答你...

看你是想要ajax還是送form表單,PHP也要另外寫

mysql 部分也不知道數據結構長怎樣

我的通靈術等級有點低,真的猜不到

0
小魚
iT邦大師 1 級 ‧ 2021-05-10 18:09:05

初學可以先從GET跟POST著手,
之後再進階到Ajax.
Google應該可以找到很多資料.

我要發表回答

立即登入回答