我希望有人可以帮助我,因为我在PHP代码中遇到了这个奇怪的错误。 首先,这是代码的相关部分:
//STEP 1b - PREPROCESSING OF SUBMITTED FORM DATA (table level)
while($count_table++ != $num_tables && $submit != ""){
$table_show[$count_table] = mysql_escape_string($_POST[table_show_.$count_table]);
$ne_page[$count_table] = mysql_escape_string($_POST[ne_page_.$count_table]);
}
//STEP 2 - SUBMITTED?
if($submit!=""){
//The form has been submitted
//STEP 3 - VALIDATION
//Reset counts
$count_column = 0;
$count_table = 0;
//Check for empty fields
while($count_table++ != $num_tables){ if($table_show[$count_table] != ""){ //While there are tables, validate only if they are in included in NexEdit
在我正在测试的场景中,if会返回false值。结果,它应该直接回到它前面的时间(我关闭时间,如果在同一点进一步)。
if($ne_page[$count_table] == ""){
$error = "You forgot to give a NexEdit name to one or more of the tables you want to include in NexEdit.";
}
echo "Debug";
正如预期的那样,这一点从未得到回应,因为PHP从未在第一时间进入过if。
while($db_field[++$count_column]){ //Stay inside the loop until we run out of db fields
if($db_field[$count_column] == "" || $db_type[$count_column] == "" || $db_table[$count_column] == "" || $ne_name[$count_column] == "" || $ne_type[$count_column] == "" || $ne_order[$count_column] == ""){ //Check if all information is entered if the column is selected to be included in NexEdit
$error = "You didn't enter all required information. Required fields are indicated with (*).";
这就是错误发生的地方:即使PHP不应该早先输入if(如调试回声所示),它仍然会在这里设置$ error的值。
}
}
}}
//More code...
我错过了什么?我已经看了几个小时,甚至向朋友开发人员寻求帮助,但我找不到我做错了什么。
一个区块中的所有代码:
//STEP 1b - PREPROCESSING OF SUBMITTED FORM DATA (table level)
while($count_table++ != $num_tables && $submit != ""){
$table_show[$count_table] = mysql_escape_string($_POST[table_show_.$count_table]);
$ne_page[$count_table] = mysql_escape_string($_POST[ne_page_.$count_table]);
}
//STEP 2 - SUBMITTED?
if($submit!=""){
//The form has been submitted
//STEP 3 - VALIDATION
//Reset counts
$count_column = 0;
$count_table = 0;
//Check for empty fields
while($count_table++ != $num_tables){ if($table_show[$count_table] != ""){ //While there are tables, validate only if they are in included in NexEdit
if($ne_page[$count_table] == ""){
$error = "You forgot to give a NexEdit name to one or more of the tables you want to include in NexEdit.";
}
echo "Debug";
while($db_field[++$count_column]){ //Stay inside the loop until we run out of db fields
if($db_field[$count_column] == "" || $db_type[$count_column] == "" || $db_table[$count_column] == "" || $ne_name[$count_column] == "" || $ne_type[$count_column] == "" || $ne_order[$count_column] == ""){ //Check if all information is entered if the column is selected to be included in NexEdit
$error = "You didn't enter all required information. Required fields are indicated with (*).";
}
}
}}
//More code...
答案 0 :(得分:2)
我的第一个想法是在某处不匹配的大括号。
你说“它应该直接回到它面前”。除非我弄错了,看起来循环在if语句之前关闭。
是否可以发布更完整/未完整的方法版本?它可能有助于诊断
答案 1 :(得分:1)
在$error
循环期间永远不会清除while
的值。所以,你认为它被填充的地方实际上是while
循环之前迭代之一的结果。