views:

32

answers:

3

html form code-

<td width="75">
<input name="txtQty[]" type="text" id="txtQty[]" size="5" 
 value="<?php echo $ct_qty; ?>" class="box" onKeyUp="checkNumber(this);">

when I submit form I calls following script-

if (!get_magic_quotes_gpc()) {
if (isset($_POST)) {
    foreach ($_POST as $key => $value) {
        $_POST[$key] =  trim(addslashes($value));
    }
}

if (isset($_GET)) {
    foreach ($_GET as $key => $value) {
        $_GET[$key] = trim(addslashes($value));
    }
}   
}

error-

Warning: addslashes() expects parameter 1 to be string, array given in C:\xampp\htdocs\shizin\products\library\config.php on line 53

I think this script is being used just to trim input but I dont know what this addslash function does and why this error coming.

A: 

the error said , the addslashes function try to Quote string with slashes , but the $value the parameter is not a string is an array, what CONTAIN the $_GET ?

its because that the page that call to this script pass a array . txtQty[]

http://php.net/manual/en/function.addslashes.php

Haim Evgi
A: 

Just echo $value before passing it to addslashes(), then you should see the problem immediately.

Mononofu
+1  A: 
  1. The whole approach is wrong.
    Upon receiving user supplied data you have to strip slashes, added by magic quotes, not add.

  2. About array approach it says 2 answers already posted, I hope it is well explained here. Not so well, but anyway.

So, you will need 2 code snippets.
A first one is stripslashes_deep() from http://www.php.net/manual/en/function.stripslashes.php

A second one you will get after you tell us, why did you think you need the code you posted.

Col. Shrapnel