ถามการส่งค่า และรับค่าคะ แบบ list menu ดึง warehouse ขึ้นมาจากฐานข้อมูลอ่ะคะ
Code (PHP)
$_POST["warehouse_id"];
Date :
2010-01-10 21:02:27
By :
plakrim
ไม่ได้อ่ะคะ
Date :
2010-01-10 21:05:25
By :
benzict063
โค๊ดมีแค่นั้นหรอครับ
Date :
2010-01-10 21:06:03
By :
plakrim
ไฟล์ที่ให้เลือก list menu
Code (PHP)
<?
include("sessionlogin.php");
?>
<?
include("connect_db.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" src="framework_prototype/prototype.js"></script>
<script language="javascript" src="allFunction.js"></script>
<script language="javascript" Charset="utf-8" src="checkOver.js"></script>
<SCRIPT language="JavaScript">
function isIntDigit(textObj){
var newValue = textObj.value;
var newLength = newValue.length;
for(var i = 0;i != newLength; i++){
aChar = newValue.substring(i,i+1);
if(aChar < "0" || aChar > "9") {
alert("กรุณาใส่ข้อมูลเป็นตัวเลขเช่น 1234567890");
textObj.value = '';
return false;
}
}
}
</script>
<style type="text/css">
<!--
.style15 {color: #FFFFFF;
font-size: 14px;
}
.style31 {
font-size: 24px;
font-weight: bold;
color: #000000;
}
.style27 {
font-size: 24px;
font-weight: bold;
color: #FFFFFF;
}
body {
background-color: #990000;
margin-left: 0px;
margin-top: 0px;
}
.style17 {font-size: 18px}
-->
</style>
</head>
<body>
<form id="form1" name="form1" method="post" action="ricegove.php">
<? echo $project_id=$_POST["project_id"]; ?>
<input type="hidden" name="project_id" value="<?=$project_id; ?>" />
<input name="warehouse_id" type="hidden" value="<?=$warehouse_id;?>"/>
<table width="900" border="0" align="center" cellpadding="0" cellspacing="0"><tr>
<td colspan="4" rowspan="2">
<table width="900" border="0" align="center" cellpadding="0" cellspacing="0" background="image/bg_footer.jpg" bgcolor="#009933">
<tr>
<td colspan="10"><img src="image/head4.jpg" width="900" height="200" /></td>
</tr>
<tr>
<td width="8" bgcolor="#742F06"> </td>
<td width="119" bgcolor="#742F06"><a href="login2.php"><img src="image/home.jpg" width="113" height="37" border="0" /></a></td>
<td width="120" bgcolor="#742F06"><a href="link.php"><img src="image/link.jpg" width="113" height="37" border="0" /></a></td>
<td width="113" bgcolor="#742F06"><a href="help.php"><img src="image/help.jpg" width="113" height="37" border="0" /></a></td>
<td width="91" bgcolor="#742F06"> </td>
<td width="91" bgcolor="#742F06"> </td>
<td width="91" bgcolor="#742F06"> </td>
<td width="91" bgcolor="#742F06"> </td>
<td width="159" bgcolor="#742F06"> </td>
<td width="17" bgcolor="#742F06"> </td>
</tr>
<tr>
<td colspan="4" rowspan="2"><img src="image/bg2.jpg" width="359" height="500" /></td>
<td colspan="6"><table width="542" height="20" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="right" bgcolor="#333333"><? include ("wellcome.php");?>
<? include ("logoutcheck.php");?></td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="6" align="right" valign="top" bgcolor="#FFFFFF"><table width="542" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="image/ข้าวแปรรูป.jpg" width="541" height="50" /></td>
</tr>
<tr>
<td><?
include("connect_db.php");
$sql="SELECT species.species_id,species.species_name,gove_quantity";
$sql .= " FROM species,stock3";
$sql .= " WHERE species.species_id = stock3.species_id";
$sql .= " GROUP BY stock3.species_id";
$query=mysql_query($sql);
if(!query){
echo "error command";
exit();
}?>
<input type="hidden" name="trans_date" id="trans_date" value="<?=date('Y-m-d')?>"/>
<table width="540" border="1" align="center" class="style27">
<tr>
<td align="center" class="style31">รหัส</td>
<td align="center" class="style31">ชนิดข้าว</td>
<td align="center" class="style31">ปริมาณ</td>
<td align="center" class="style31">ปริมาณที่ต้องการโอน</td>
</tr>
<?
$count=0;
while($row=mysql_fetch_array($query))
{?>
<tr>
<td class="style31" align="center"><? echo $row[0]; ?></td>
<td align="left" class="style31" ><? echo $row[1]; ?></td>
<td class="style31" align="center"><? echo number_format($row[2]); ?> <? print "<input name=num1[$count] type=hidden value=".$row[2]." >"; ?>
<? print "<input name=species_id[$count] type=hidden value=".$row[0]." >"; ?></td>
<td class="style31" align="center"> <? print "<input name=num2[$count] type=text onkeyup=isIntDigit(this) onkeydown=isIntDigit(this) onchange=checkOver(this,$row[2],$count)>"; ?></td>
</tr>
<input type="hidden" name="input1" />
<script language="javascript">
//createTagDiv();
</script>
<?
$count++;
}
?>
</table></td>
</tr>
</table>
<span class="style17">
<?
include("connect_db.php");
$result_spe=mysql_query("SELECT * FROM warehouse ORDER BY warehouse_id");
$row_spe=mysql_num_rows($result_spe);
?>
<select name="warehouse_id">
<option value="0">-- กรุณาเลือก --</option>
<? while($dbarr_spe = mysql_fetch_array($result_spe)){ ?>
<option value="<?=$dbarr_spe['warehouse_id'];?>"><? echo $dbarr_spe['warehouse_name']; ?></option>
<? } ?>
</select>
<input type="hidden" name="warehouse_id" value="<?=$warehouse_id;?>"/>
</span> <span class="style17"></span>
<input type="button" name="button" id="button" value="โอนและออกใบส่งสินค้า" onclick="check()"/> </td>
</tr>
<tr>
<td></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
ไฟล์รับค่ามาเก็บลงฐานข้อมูล
Code (PHP)
<?
include("connect_db.php");
$num1=$_POST["num1"];
$num2=$_POST["num2"];
$species_id=$_POST["species_id"];
$project_id=$_POST["project_id"];
$warehouse_id=$_POST["warehouse_id"];
include("functionCheck.php");
insert3($trans_date,$species_id,$trans_stock,$num2,$warehouse_id,$project_id);
update1("stock3",$num1,$num2,$species_id,$project_id);
update2("stock4",$num2,$species_id,$project_id);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style15 {color: #FFFFFF;
font-size: 14px;
}
.style27 { font-size: 24px;
font-weight: bold;
color: #FFFFFF;
}
.style31 { font-size: 24px;
font-weight: bold;
color: #000000;
}
body {
background-color: #990000;
}
-->
</style>
</head>
<body>
<table width="900" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="10"><img src="image/head4.jpg" width="900" height="200" /></td>
</tr>
<tr>
<td width="8" bgcolor="#742F06"> </td>
<td width="119" bgcolor="#742F06"><a href="login2.php"><img src="image/home.jpg" width="113" height="37" border="0" /></a></td>
<td width="120" bgcolor="#742F06"><a href="link.php"><img src="image/link.jpg" width="113" height="37" border="0" /></a></td>
<td width="113" bgcolor="#742F06"><a href="help.php"><img src="image/help.jpg" width="113" height="37" border="0" /></a></td>
<td width="91" bgcolor="#742F06"> </td>
<td width="91" bgcolor="#742F06"> </td>
<td width="91" bgcolor="#742F06"> </td>
<td width="91" bgcolor="#742F06"> </td>
<td width="159" bgcolor="#742F06"> </td>
<td width="17" bgcolor="#742F06"> </td>
</tr>
<tr>
<td colspan="4" rowspan="2"><img src="image/bg2.jpg" width="359" height="500" /></td>
<td colspan="6"><table width="542" height="20" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="right" bgcolor="#333333"><? include ("wellcome.php");?>
<? include ("logoutcheck.php");?></td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="6" align="left" valign="top"><?
$sql="SELECT species.species_id,species.species_name,gove_quantity";
$sql .= " FROM species,stock4";
$sql .= " WHERE species.species_id = stock4.species_id";
$sql .= " GROUP BY stock4.species_id";
$query=mysql_query($sql);
if(!$query){
echo "error command";
exit();
}?>
<input type="hidden" name="trans_date" id="trans_date" value="<?=date('Y-m-d')?>"/>
<? echo $warehouse_id;?>
<table width="540" border="1" align="center" class="style27">
<tr>
<td colspan="3" align="center" class="style31"><div align="left"><img src="image/ข้าวจัดส่งรัฐบาล.jpg" width="529" height="50" /></div></td>
</tr>
<tr>
<td align="center" class="style31">รหัส</td>
<td align="center" class="style31">ชนิดข้าว</td>
<td align="center" class="style31">ปริมาณ</td>
</tr>
<?
$row=mysql_num_rows($query);
$i=1;
while($i<=$row){
$data=mysql_fetch_array($query);
$data1=$data['species_id'];
$data2=$data['species_name'];
$data3=$data['gove_quantity'];
?>
<tr>
<td class="style31" align="center"><? echo $data1; ?></td>
<td align="left" class="style31" ><? echo $data2; ?></td>
<td class="style31" align="center"><? echo number_format($data3);
/*
for($i=0;$i<count($amount);$i++){
$cal[$i]=$quantity[$i]-$amount[$i];
}
foreach($cal as $c){
echo $c;
}
*/
?></td>
</tr>
<? $i++;} //end while ?>
</table>
<p align="center"> </p>
</td>
</tr>
<tr>
<td height="71" colspan="10" align="center" background="image/bg_footer.jpg" bgcolor="#742F06"><span class="style15">COPY RIGHT RICE PAWN SYSTEM @ MERCEDES ICT 13490063 </span></td>
</tr>
</table>
</body>
</html>
ไฟล์ js ที่เขียน function เก็บลงฐานข้อมูล
Code
function insert3($trans_date,$species_id,$trans_stock,$num2,$warehouse_id,$project_id)
{
$i=1;
$count=0;
while($i<=count($num2)){
$sql_check="select * from transfer where species_id='$species_id[$count]' and project_id='$project_id'";
$query_check=mysql_query($sql_check);
if(!$query_check){
echo "error check";
exit();
}
$gove_quantity=$num2[$count];
$trans_stock='3';
$sql_check2="insert into transfer(trans_date,trans_stock,species_id,gove_quantity,project_id,warehouse_id) value('$trans_date','$trans_stock','$species_id[$count]','$gove_quantity','$project_id','$warehouse_id')";
$queryin=mysql_query($sql_check2);
if(!$queryin){
echo "error check ka";
exit();
}
$i++;
$count++;
}
}//end
รบกวนช่วยดูหน่อยนะคะ
Date :
2010-01-10 21:23:38
By :
benzict063
ชื่อใน hidden กับ dropdownlist เหมือนกัน ลองเปลี่ยนดูครับ
Date :
2010-01-10 21:40:25
By :
plakrim
ยังไม่ได้คะ
ฮื่อออ
Date :
2010-01-10 21:50:34
By :
benzict063
<input name="warehouse_id" type="hidden" value="<?=$warehouse_id;?>"/>
คือกันกับ
<select name="warehouse_id">
Date :
2010-01-10 21:59:24
By :
plakrim
เหมือนค่าไม่ส่งไปอ่ะคะ
เพราะลอง echo หน้าที่รับค่าแล้ว มันไม่มีอะไรขึ้นมาเรยอ่ะคะ
Date :
2010-01-10 22:06:19
By :
benzict063
print_r($_POST);
แล้ว copy มาดูครับ
Date :
2010-01-10 22:13:58
By :
plakrim
ลองเอาโค้ดที่พี่ให้มาแปะไว้แล้วขึ้นแบบนี้ค่ะ
Array ( [project_id] => 1 [warehouse_id] => [trans_date] => 2010-01-10 [num1] => Array ( [0] => 259980 [1] => 130 [2] => 130 [3] => 130 [4] => 130 [5] => 130 [6] => 130 ) [species_id] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 10 ) [num2] => Array ( [0] => 10 [1] => 10 [2] => 10 [3] => 10 [4] => 10 [5] => 10 [6] => 10 ) [input1] => 10 [warehouse] => 2 )
Date :
2010-01-10 22:19:17
By :
benzict063
<?
include("sessionlogin.php");
?>
<?
include("connect_db.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" src="framework_prototype/prototype.js"></script>
<script language="javascript" src="allFunction.js"></script>
<script language="javascript" Charset="utf-8" src="checkOver.js"></script>
<SCRIPT language="JavaScript">
function isIntDigit(textObj){
var newValue = textObj.value;
var newLength = newValue.length;
for(var i = 0;i != newLength; i++){
aChar = newValue.substring(i,i+1);
if(aChar < "0" || aChar > "9") {
alert("กรุณาใส่ข้อมูลเป็นตัวเลขเช่น 1234567890");
textObj.value = '';
return false;
}
}
}
</script>
<style type="text/css">
<!--
.style15 {color: #FFFFFF;
font-size: 14px;
}
.style31 {
font-size: 24px;
font-weight: bold;
color: #000000;
}
.style27 {
font-size: 24px;
font-weight: bold;
color: #FFFFFF;
}
body {
background-color: #990000;
margin-left: 0px;
margin-top: 0px;
}
.style17 {font-size: 18px}
-->
</style>
</head>
<body>
<form id="form1" name="form1" method="post" action="ricegove.php">
<? echo $project_id=$_POST["project_id"]; ?>
<input type="hidden" name="project_id" value="<?=$project_id; ?>" />
<input name="warehouse_id" type="hidden" value="<?=$warehouse_id;?>"/>
<table width="900" border="0" align="center" cellpadding="0" cellspacing="0"><tr>
<td colspan="4" rowspan="2">
<table width="900" border="0" align="center" cellpadding="0" cellspacing="0" background="image/bg_footer.jpg" bgcolor="#009933">
<tr>
<td colspan="10"><img src="image/head4.jpg" width="900" height="200" /></td>
</tr>
<tr>
<td width="8" bgcolor="#742F06"> </td>
<td width="119" bgcolor="#742F06"><a href="login2.php"><img src="image/home.jpg" width="113" height="37" border="0" /></a></td>
<td width="120" bgcolor="#742F06"><a href="link.php"><img src="image/link.jpg" width="113" height="37" border="0" /></a></td>
<td width="113" bgcolor="#742F06"><a href="help.php"><img src="image/help.jpg" width="113" height="37" border="0" /></a></td>
<td width="91" bgcolor="#742F06"> </td>
<td width="91" bgcolor="#742F06"> </td>
<td width="91" bgcolor="#742F06"> </td>
<td width="91" bgcolor="#742F06"> </td>
<td width="159" bgcolor="#742F06"> </td>
<td width="17" bgcolor="#742F06"> </td>
</tr>
<tr>
<td colspan="4" rowspan="2"><img src="image/bg2.jpg" width="359" height="500" /></td>
<td colspan="6"><table width="542" height="20" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="right" bgcolor="#333333"><? include ("wellcome.php");?>
<? include ("logoutcheck.php");?></td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="6" align="right" valign="top" bgcolor="#FFFFFF"><table width="542" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="image/ข้าวแปรรูป.jpg" width="541" height="50" /></td>
</tr>
<tr>
<td><?
include("connect_db.php");
$sql="SELECT species.species_id,species.species_name,gove_quantity";
$sql .= " FROM species,stock3";
$sql .= " WHERE species.species_id = stock3.species_id";
$sql .= " GROUP BY stock3.species_id";
$query=mysql_query($sql);
if(!query){
echo "error command";
exit();
}?>
<input type="hidden" name="trans_date" id="trans_date" value="<?=date('Y-m-d')?>"/>
<table width="540" border="1" align="center" class="style27">
<tr>
<td align="center" class="style31">รหัส</td>
<td align="center" class="style31">ชนิดข้าว</td>
<td align="center" class="style31">ปริมาณ</td>
<td align="center" class="style31">ปริมาณที่ต้องการโอน</td>
</tr>
<?
$count=0;
while($row=mysql_fetch_array($query))
{?>
<tr>
<td class="style31" align="center"><? echo $row[0]; ?></td>
<td align="left" class="style31" ><? echo $row[1]; ?></td>
<td class="style31" align="center"><? echo number_format($row[2]); ?> <? print "<input name=num1[$count] type=hidden value=".$row[2]." >"; ?>
<? print "<input name=species_id[$count] type=hidden value=".$row[0]." >"; ?></td>
<td class="style31" align="center"> <? print "<input name=num2[$count] type=text onkeyup=isIntDigit(this) onkeydown=isIntDigit(this) onchange=checkOver(this,$row[2],$count)>"; ?></td>
</tr>
<input type="hidden" name="input1" />
<script language="javascript">
//createTagDiv();
</script>
<?
$count++;
}
?>
</table></td>
</tr>
</table>
<span class="style17">
<?
include("connect_db.php");
$result_spe=mysql_query("SELECT * FROM warehouse ORDER BY warehouse_id");
$row_spe=mysql_num_rows($result_spe);
?>
<select name="warehouse_id">
<option value="0">-- กรุณาเลือก --</option>
<? while($dbarr_spe = mysql_fetch_array($result_spe)){ ?>
<option value="<?=$dbarr_spe['warehouse_id'];?>"><? echo $dbarr_spe['warehouse_name']; ?></option>
<? } ?>
</select>
<input type="hidden" name="warehouse_id" value="<?=$warehouse_id;?>"/>
</span> <span class="style17"></span>
<input type="button" name="button" id="button" value="โอนและออกใบส่งสินค้า" onclick="check()"/> </td>
</tr>
<tr>
<td></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
สีแดงๆ สองที่เอาออกครับ
ไม่ทราบว่ามีไว้ทำไม
Date :
2010-01-10 23:03:28
By :
plakrim
เอาออกแล้วคะ
มันวนเข้าฟังก์ชันนี้ แล้วบอกว่า error check ka อ่ะคะ
Code
function insert3($trans_date,$species_id,$trans_stock,$num2,$warehouse_id,$project_id)
{
$i=1;
$count=0;
while($i<=count($num2)){
$sql_check="select * from transfer where species_id='$species_id[$count]' and project_id='$project_id'";
$query_check=mysql_query($sql_check);
if(!$query_check){
echo "error check";
exit();
}
$gove_quantity=$num2[$count];
$trans_stock='3';
$sql_check2="insert into transfer(trans_date,trans_stock,species_id,gove_quantity,project_id,warehouse_id) value('$trans_date','$trans_stock','$species_id[$count]','$gove_quantity','$project_id','$warehouse_id')";
$queryin=mysql_query($sql_check2);
if(!$queryin){
echo "error check ka";
exit();
}
$i++;
$count++;
}
}//end
Date :
2010-01-10 23:14:34
By :
benzict063
$sql_check2="insert into transfer(trans_date,trans_stock,species_id,gove_quantity,project_id,warehouse_id) values ('$trans_date','$trans_stock','$species_id[$count]','$gove_quantity','$project_id','$warehouse_id')";
เออ เอาโค๊ดเค้ามาหรือเขียนเองครับเนี้ย
Date :
2010-01-10 23:23:52
By :
plakrim
ตาลายยย
Date :
2010-01-10 23:30:22
By :
panyapol
งะ เขียนเองคะ
พี่ค่ะ values ต้องมี s ด้วยหรอคะ
หนูเขียนอันอื่นไม่เหงต้องมีเรยยยยยยย
แล้วลองมี s ก้อเหมือนเดิมอ่ะคะ
ขึ้น error check ka
Date :
2010-01-10 23:30:36
By :
benzict063
$queryin=mysql_query($sql_check2) or die(mysql_error());
Date :
2010-01-10 23:33:27
By :
plakrim
ขึ้น Incorrect integer value: '' for column 'warehouse_id' at row 1
ฮื่ออออ
Date :
2010-01-10 23:37:25
By :
benzict063
หนูลองไปเปลี่ยน จาก int เปง varchar แล้ว ผ่านคะ แต่ไม่มีข้อมูลใน db (ไม่ขึ้น null นะคะ เป้นช่องว่างๆเลย- -)
Date :
2010-01-10 23:42:00
By :
benzict063
$queryin=mysql_query($sql_check2) or die("Message:".mysql_error()."<br>SQL:".$sql_check2);
Date :
2010-01-10 23:42:08
By :
plakrim
พี่ค่ะะะะะะะะะะะะะะะะ
ได้แล้วค่ะ
หนูไปแก้ชื่อ warehouse ตรงที่เลือกไม่ตรงกับที่ส่งไป
ขอบคุณพีมากๆๆๆๆๆๆๆๆๆๆๆๆๆๆๆๆๆๆๆๆๆๆๆๆๆๆเลยนะคะ
Date :
2010-01-10 23:48:21
By :
benzict063
Load balance : Server 05