2013-07-25 50 views
0

我已經收到此錯誤:一個PHP錯誤遇到笨

A PHP Error was encountered Severity: Warning Message: strip_tags() expects parameter 1 to be string, array given Filename: inscription/loginform3.php Line Number: 19

這裏是代碼:

echo form_open_multipart('user/register_step_3'); 

// Loop through the POST variables passed from the previous page 
foreach ($_POST as $key => $value){ 
    $value = htmlentities(stripslashes(strip_tags($value))); 
    echo form_hidden($key, $value); 
} 

和線路19的代碼:

$value = htmlentities(stripslashes(strip_tags($value))); 

請幫我與這個問題。

+0

您可以將print_r($ value)粘貼到此處嗎? –

+1

'$ value'是一個數組,它可能有另一個元素,比如'$ value [0]' – 2013-07-25 01:14:49

+1

你看過CodeIgniter的[input class](http://ellislab.com/codeigniter/user-guide/libraries/ input.html)和'$ this-> input-> post'? – jleft

回答

0

請檢查您的形式,如果給出數組 任何輸入標籤是指:

<input type="checkbox" name="check[]" /> 

如果數組字段爲有你需要使用一個更內環如:

foreach ($_POST as $key => $value){ 
    if(is_array($value)){ 
    // Inner loop 
    foreach ($value as $k => $v){ 
     // Code 
    } 
    }else{ 
    $value = htmlentities(stripslashes(strip_tags($value))); 
    echo form_hidden($key, $value); 
    } 
} 

oherwise嘗試此代碼:

foreach ($_POST as $key => $value){ 
    $val = htmlentities(stripslashes(strip_tags($_POST[$key]))); 
    echo form_hidden($key, $val); 
}