 |
นำตัวแปร $ มาต่อกับ name ของ textbox ใน $_POST แล้ว error คะ |
|
 |
|
|
 |
 |
|
ลองแบบนี้ดูครับ
Code (PHP)
$strxxx="check".$i;//เอาไปวางก่อน if เสร็จแล้วนำ $strxxx ไปแทนที่ $_POST[$strxxx]
|
ประวัติการแก้ไข 2013-09-23 08:30:21
 |
 |
 |
 |
Date :
2013-09-23 08:28:56 |
By :
namebom |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
$strxxx="check_".$i;
$_POST[$strxxx];
|
 |
 |
 |
 |
Date :
2013-09-23 09:30:47 |
By :
anotherdie |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โค้ดเขียน {} เกินมาครับ หรือไม่ตรงกับโครงสร้างคำสั่ง มันจึง error
for ($i=1;$i<=100;$i++)
{
$chk_post = 'check_'.$i;
if ($_POST[$chk_post] != '')
{
$sql = "SELECT * FROM ons_check WHERE id = '$_POST[$chk_post]' order by id asc";
$result = mysql_query($sql) or die(mysql_error());
$datas=mysql_fetch_array($result);{ //ตรงนี้เกินมา
$check_full_text_."".$i = stripslashes(str_replace('\r\n', '<br>',($datas['addons_check'])));
$check_price_."".$i = stripslashes(str_replace('\r\n', '<br>',($datas['addons_price'])));
} //กับตรงนี้
$_SESSION[addons_check_full_text_."".$i] = $check_full_text_."".$i;
$_SESSION[addons_check_price_."".$i] = $check_price_."".$i;
}
}
โค้ดที่แก้แล้ว และเพิ่ม $result = mysql_query($sql) or die(mysql_error()); เพื่อเช็คว่า sql ทำงานได้หรือไม่?
Code (PHP)
for ($i=1;$i<=100;$i++)
{
$chk_post = 'check_'.$i;
if ($_POST[$chk_post] != '')
{
$sql = "SELECT * FROM ons_check WHERE id = '$_POST[$chk_post]' order by id asc";
$result = mysql_query($sql) or die(mysql_error());
$datas=mysql_fetch_array($result);
$check_full_text_."".$i = stripslashes(str_replace('\r\n', '<br>',($datas['addons_check'])));
$check_price_."".$i = stripslashes(str_replace('\r\n', '<br>',($datas['addons_price'])));
$_SESSION[addons_check_full_text_."".$i] = $check_full_text_."".$i;
$_SESSION[addons_check_price_."".$i] = $check_price_."".$i;
}
}
|
ประวัติการแก้ไข 2013-09-23 09:54:16 2013-09-23 09:55:19 2013-09-23 09:56:45
 |
 |
 |
 |
Date :
2013-09-23 09:53:49 |
By :
arm8957 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
if ($_POST["check_" . $i] != '')
$sql = "SELECT * FROM ons_check WHERE id = '" . $_POST["check_" . $i] . "' order by id asc";
สำหรับมือใหม่เชื่อม string แบบนี้ จะได้เห็นความแต่แตงด้วย syntax highlighter ของแต่ละ ide จะได้เข้าใจง่าย ไม่ตกหล่นนะครับ
|
 |
 |
 |
 |
Date :
2013-09-23 10:11:25 |
By :
PlaKriM |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|