ช่วยดูหน่อยครับ ข้อมูลมันไม่ insert ผมหาไม่เจออ่ะครับ งมอยู่นานมาก
ฟอร์ม(PHP)
<?
include_once '../includes/connect.php';
?>
<script src="../includes/js/jquery/jquery.form.js" type="text/javascript"></script>
<script type="text/javascript" src="../includes/js/jquery/jquery.datepick.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#myForm").submit(function () {
if($("#popupDatepicker").val() == ''){
alert("คุณไม่ได้กรอก วันที่");
return false;
}
else if($("#ph").val() == ''){
alert("คุณไม่ได้กรอกค่า ph");
return false;
}
else if($("#temp").val() == 'เช้า:'){
alert("คุณไม่ได้กรอกค่า อุณหภูมิ");
return false;
}
else if($("#lux").val() == 'เช้า:'){
alert("คุณไม่ได้กรอกค่า ความเข้มแสง");
return false;
}
else if($("#grow").val() == ''){
alert("คุณไม่ได้กรอกค่า ความเจริญเติบโต");
return false;
}
else if($("#product").val() == ''){
alert("คุณไม่ได้กรอกค่า ผลผลิต");
return false;
}
});
});
</script>
<script type="text/javascript">
$(function() {
$('#popupDatepicker').datepick({dateFormat: 'yyyy-mm-dd'});
$('#inlineDatepicker').datepick({onSelect: showDate});
});
function showDate(date) {
alert('The date chosen is ' + date);
}
</script>
<script type="text/javascript">
$(document).ready(function() {
$('#myForm').ajaxForm({
dataType: 'json',
success: function processJson(resPonse) {
if(resPonse==1){
$('#Loading').hide();
$('#Loading1').show();
$('#Loading1').fadeOut(1500);
$('#myForm').reset();
} else {
$('#Loading1').hide();
$('#Loading').show();
$('#Loading1').show(1500);
}
}
});
});
function clearValue(obj,text) {
if ( obj.value == text ) obj.value = '';
}
function checkValue(obj,text) {
if ( obj.value == '' ) obj.value = text;
}
</script>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr><td style="border: 1px dashed #dedbd1; padding: 6px; margin: 1px; background-color: #ebe9e1; font-weight: bold; font-size: 15px;">เพิ่มข้อมูลการทดลอง</td></tr>
<tr>
<td align="left" style="padding-left:5px; height:29px; line-height:29px;"><a href="javascript:LoadContentDIV('dataAdd.php');">[+] เพิ่มข้อมูลรายบ่อ</a></td></tr>
</table>
<form name="myForm" id="myForm" method="post" action="dataAdd2_script.php" autocomplete="off">
<table width="100%" cellpadding="9" cellspacing="0" border="0">
<tr>
<td width="5%" class="TD_title">วันที่: </td> <td align="left" width="95%"><input name="popupDatepicker" type="text" class="textbox" value="<? echo date('Y-m-d')?>" id="popupDatepicker" > </td>
</tr>
</table>
<table id="tb" width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#dedbd1">
<tr>
<td width="7%" height="25" rowspan="2" align="center" bgcolor="#ebe9e1"><strong>บ่อ</strong></td>
<td width="7%" height="25" rowspan="2" align="center" bgcolor="#ebe9e1"><strong>PH</strong></td>
<td height="20" colspan="2" align="center" bgcolor="#ebe9e1"><strong>อุณหภูมิ</strong></td>
<td height="20" colspan="2" align="center" bgcolor="#ebe9e1"><strong>ความเข้มแสง</strong></td>
<td width="11%" height="25" rowspan="2" align="center" bgcolor="#ebe9e1"><strong>การเจริญเติบโต</strong></td>
<td width="7%" height="25" rowspan="2" align="center" bgcolor="#ebe9e1"><strong>น้ำหนักเปียก</strong></td>
<td width="7%" height="25" rowspan="2" align="center" bgcolor="#ebe9e1"><strong>น้ำหนักแห้ง</strong></td>
</tr>
<tr>
<td width="10%" height="25" align="center" bgcolor="#EBE9E1">เช้า</td>
<td width="10%" height="25" align="center" bgcolor="#EBE9E1">บ่าย</td>
<td width="7%" height="25" align="center" bgcolor="#EBE9E1">เช้า</td>
<td width="7%" height="25" align="center" bgcolor="#EBE9E1">บ่าย</td>
</tr>
<?
$pools = Query("select * from algaepool where status = 'y' order by name asc");
$poolNumrows = mysql_num_rows($pools);
while($rows = mysql_fetch_array($pools))
{ ?>
<tr>
<input type="hidden" name="hdnLine" value="<?=$i;?>">
<td height="25" align="center" bgcolor="#FFFFFF"><?=$rows["name"]?></td>
<td height="25" align="center" bgcolor="#FFFFFF"><label>
<input type="text" name="ph<?=$i;?>" id="ph<?=$i;?>" class="textboxshort" />
</label></td>
<td height="25" align="center" bgcolor="#FFFFFF"><label>
<input type="text" name="temp<?=$i;?>" id="temp<?=$i;?>" class="textboxshort" />
</label></td>
<td height="25" align="center" bgcolor="#FFFFFF"><label>
<input type="text" name="temp_after<?=$i;?>" id="temp_after<?=$i;?>" class="textboxshort" />
</label></td>
<td height="25" align="center" bgcolor="#FFFFFF"><label>
<input type="text" name="lux<?=$i;?>" id="lux<?=$i;?>" class="textboxshort" />
</label></td>
<td height="25" align="center" bgcolor="#FFFFFF"><label>
<input type="text" name="lux_after<?=$i;?>" id="lux_after<?=$i;?>" class="textboxshort" />
</label></td>
<td height="25" align="center" bgcolor="#FFFFFF"><label>
<input type="text" name="grow<?=$i;?>" id="grow<?=$i;?>" class="textboxshort" />
</label></td>
<td height="25" align="center" bgcolor="#FFFFFF"><label>
<input type="text" name="wet<?=$i;?>" id="wet<?=$i;?>" class="textboxshort" />
</label></td>
<td height="25" align="center" bgcolor="#FFFFFF"><label>
<input type="text" name="dry<?=$i;?>" id="dry<?=$i;?>" class="textboxshort" />
</label></td>
</tr>
<? } ?>
</table>
<br />
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div id="buttonDiv"><input type="submit" name="button1" value="บันทึก" class="button" >
<input type="button" name="button2" value="ย้อนกลับ" onclick="javascript:LoadContentDIV('timeList.php');" class="button"></div>
<div id="Loading" style="padding: 10px; text-align: center; display:none; color: red;"><img src="../images/loader_twt.gif" /> กำลังบันทึกข้อมูล..</div></td>
</tr>
</table>
</form>
Code (PHP)
<?php
session_start();
include_once "../includes/connect.php";
$_dateInsert = $_POST["popupDatepicker"];
$_user = $_SESSION["user"];
$_ph = $_POST["ph$i"];
$_idpool = $_POST["pool$i"];
$_temp = $_POST["temp$i"];
$_temp_after = $_POST["temp_after$i"];
$_lux = $_POST["lux$i"];
$_alux_after = $_POST["lux_after$i"];
$_grow = $_POST["grow$i"];
$_wet = $_POST["wet$i"];
$_dry = $_POST["dry$i"];
for($i=1;$i<=$_POST["hdnLine"];$i++)
{
if($_ph != '')
{
$result = Query("INSERT INTO algaeevaluate (user,ph,idpool,lux,lux_after,temp,temp_after,grow,wet,dry,dateInsert)
VALUES ('$_user','$_ph','$_idpool','$_lux','$_lux_after','$_temp','$_temp_after','$_grow','$_wet','$_dry','$_dateInsert')");
}
}
if($result){
echo '1';
} else {
echo '0';
}
}
?>
กดบันทึกแล้วมันนิ่งเลยครับ ผม insert หลาย record ใน หน้าเดียวกัน table เดียวกันอ่ะครับ
ช่วยผมด้วยครับ TTTag : PHP, MySQL, HTML/CSS
Date :
2010-09-07 15:09:51
By :
dev_ngo
View :
783
Reply :
5
ลอง echo เอาคำสั่ง sql ไปลองใน phpmyadmin พวกเครื่องมือ mysql รึยังครับ
Date :
2010-09-07 15:30:29
By :
tbase
มันเป็น array ครับผมไม่เข้าใจอ่ะ
Date :
2010-09-07 15:39:49
By :
dev_ngo
งั้นลองใช้ print_r
Date :
2010-09-07 15:40:58
By :
tbase
เมื่อกี๊พิมพ์ไปตั้งเยอะ หายหมดเลย.. งั้นเอาใหม่สั้นๆ
มีข้อสงสัยครับ 2-3 ข้อครับ
Code (HTML)
<input type="hidden" name="hdnLine" value="<?=$i;?>">
.
.
.
<input type="text" name="ph<?=$i;?>" id="ph<?=$i;?>" class="textboxshort" />
$i มาจากไหนครับ ผมว่าน่าจะประกาศไว้ก่อน while loop นะ
แล้วทีนี้ผมคิดว่า $i ก็คงเรียบลำดับจาก มากไปน้อย 1,2,3,4,....
ก็ให้ $i++ ตรงท้ายก่อนจบ while loop
ส่วนตอนรับค่ามาเอาตัวแปรไปไว้ใน double quote (") มันก็มองเป็นตัวอักษรครับ
Code (PHP)
$_ph = $_POST["ph$i"]; // แก้เป็น $_POST["ph".$i]; เชื่อมตัวอักษรกับตัวแปรด้วย dot (.) หรือ comma (,)
แต่ทีนี้อันเดิม มันก็มองไม่เห็น $i ครับ นอกจากไปรับค่าตัีวแปรไ้ว้ใน for loop
อันนี้ข้อเสริมครับ ไม่รู้ว่าจะเห็นยังไง
ส่วนตัวผมถ้าใช้เป็น $i ใน html form แบบนี้มันลำบากผมเกินไปครับ (ขี้ลืม+ขี้เกียจ)
ผมจะเปลี่ยนชื่อ (name) ให้มันเป็นแบบนี้ ชื่อ_text_field[] คือ ชื่อ text field แล้วตามด้วย [] น่ะครับ
ถ้ามองเป็นแบบ GET มันจะส่งมาแบบนี้ครับ ?xxx=&ph[]=1111&ph[]=2222
ทีนี้ตอนรับมาใช้ ก็ทีเดียวด้านบนของโค้ดเลยแบบไม่มี $i ต่อท้าย เพราะมันเห็นเป็น array ครับ รับทีเดียวจบ พอแล้ว
$_ph = $_POST["ph"];
พอตอนเอาไปใช้ใน loop ก็ $_ph[$i] เอาเลย โดยเริ่ม $i ที่ 0 น่ะครับ ตามหลักการใช้งานของ array
ประวัติการแก้ไข 2010-09-07 16:32:47 2010-09-07 16:37:19 2010-09-07 16:38:19
Date :
2010-09-07 16:32:01
By :
tbase
ผมปรับ ฟอร์มให้เป็นแบบที่ว่าแล้วครับ
text_field []
แต่ code insert มันผิดตรงไหนรึป่าวครับมันไม่ทำงาน
Code (PHP)
<?php
session_start();
include_once "../includes/connect.php";
$_dateInsert = $_POST["popupDatepicker"];
$_user = $_SESSION["user"];
$_ph = $_POST["ph"];
$_idpool = $_POST["pool"];
$_temp = $_POST["temp"];
$_temp_after = $_POST["temp_after"];
$_lux = $_POST["lux"];
$_alux_after = $_POST["lux_after"];
$_grow = $_POST["grow"];
$_wet = $_POST["wet"];
$_dry = $_POST["dry"];
for($i=0;$i<=1;$i++)
{
if($_ph != '')
{
$result = Query("INSERT INTO algaeevaluate (user,ph,idpool,lux,lux_after,temp,temp_after,grow,wet,dry,dateInsert)
VALUES ('$_user','$_ph','$_idpool','$_lux','$_lux_after','$_temp','$_temp_after','$_grow','$_wet','$_dry','$_dateInsert')");
}
}
if($result){
echo '1';
} else {
echo '0';
}
}
?>
Date :
2010-09-07 17:53:03
By :
dev_ngo
Load balance : Server 00