|
 |
|
สอบถามหน่อยครับถ้าผมอยากเก็บข้อมูลตามภาพผมจะต้องเขียนยังไงครับ |
|
 |
|
|
 |
 |
|
ajax/jquery เลย 
เขียนให้ดูแบบคร่าวๆน่ะครับ
Supply : <input type='text' name='supply' id='supplyText' /> <input type='button' id='saveSupply' value='บันทึก' /> <br />
Department : <input type='text' name='depart' id='departText' /> <input type='button' id='saveDepart' value='บันทึก' /> <br />
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#saveSupply").click(function(){
$.post('add_newstuff.php' ,{ act:'supply',value:$("#supplyText").val() } , function(data){
alert(data);
});
});
$("#saveDepart").click(function(){
$.post('add_newstuff.php' ,{ act:'department',value:$("#departText").val() } , function(data){
alert(data);
});
});
});
</script>
add_newstuff.php
<?php
// โค้ดส่วนติดต่อฐานข้อมูล ผมเขียนใช้เองน่ะครับ คุณเปลี่ยนเป็นมาตรฐานทั่วไปแล้วกันครับ
$db = new DB();
$db->connect();
if( isset($_POST["act"] , $_POST["value"]) && !empty($_POST["value"]) ){
if($_POST["act"] == "supply"){
$sql = "insert into supply(supplyname) values('{$_POST["value"]}')";
}elseif($_POST["act"] == "department"){
$sql = "insert into department(departname) values('{$_POST["value"]}')";
}
$db->dbquery($sql);
if($db->affected_rows()>0)
echo "บันทึกข้อมูล {$_POST["act"]} สำเร็จแล้วครับ";
else
echo "ไม่สามารถบันทึกข้อมูลได้ กรุณาแจ้งแอดมินครับ";
}else{
echo "กรุณาป้อนข้อมูลให้ครบด้วยครับ";
}
?>
|
 |
 |
 |
 |
Date :
2014-11-21 08:24:28 |
By :
cowboycnx |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|