2011-12-02 7 views
0

私はこの奇妙なバグを自分のPHPコードで困惑しているので、ここの誰かが私を助けてくれることを願っています。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 

このシナリオでは、私は、返品の場合は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"; 

期待どおり、これは決してエコーされません。

    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は入っていないはずにもかかわらず。

  } 
     } 
    }} 

//More code... 

私は何が欠けていますか?私はこれを数時間見ていて、友人の開発者に援助を依頼しましたが、私が間違ったことを見つけることはできません。


1ブロック内のすべてのコード:

//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... 
+3

!= ""の代わりに空文字列またはis_nullを使用し、他のチェックでは!==を使用して開始するのはなぜですか。それはより効果的にデバッグするのに役立ちます。男、正に、私はここで何が起こっているのかは分かりません。関連するすべてのコードを1つのブロックに入れることができますか?文脈なしであなたを助けるのは難しい。 –

+1

また、 'var_dump()'にチェックを入れて評価するものを見ることもできます。たとえば、 'var_dump($ ne_page [$ count_table] ==" ");'は真または偽を出力します。 – Treffynnon

+0

元の投稿の1つのブロックにコード全体を追加しました。私もあなたの提案を試してみるだろうし、できるだけ早くあなたに報告します。 – DriesOeyen

答えて

2

私の最初の考えはどこか不一致中括弧だろう。

あなたは "それはちょうどそれの前に真っ直ぐに戻るべきだ"と言う。間違っていない限り、if文の前にループが閉じているように見えます。

投稿の方法の完全版/未公開版は投稿できますか?診断に役立つ可能性があります

+0

不一致の中括弧はチェックされましたが、すべて一致しています。私はこれを早めにチェックし、誰か他の人にそれをチェックして何かを逃していないことを確認してもらった。 元の質問にコードブロックを追加しました。 – DriesOeyen

+0

どのエラーが返されていますか?そうすれば、意図せずに実行されていることがわかります。 –

+0

返されたエラーは表示されません。「必要な情報はすべて入力していません。必須フィールドは(*)で示されています。」 実際、最初のエラーは同様のシナリオでは表示されません。それはかなり変です。 – DriesOeyen

1

whileループ中に$errorの値は決してクリアされません。だから、実際に満たされていると思うところは、実際にはループの前の繰り返しの1つで、結果はwhileです。

+0

これは実際には設計によるものです。私は後でコード内でエラー値を使用しないので、whileループではクリアしないでください。 – DriesOeyen

+0

テストしたシナリオでは、検証しない値が1つしかないので、whileループの他のケースでは$エラーは返されません。 – DriesOeyen

関連する問題