6 Replies - 1059 Views - Last Post: 09 November 2013 - 03:42 PM Rate Topic: -----

#1 dave_6_10  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 55
  • Joined: 19-March 08

Warning: stripslashes() expects parameter 1 to be string, array given

Posted 09 November 2013 - 10:47 AM

So I get the basic idea that I am calling for an array instead of a string here. I am thinking that some sort of incorporation of stripslashes_deep may work for me here. I am really just getting hung up on this one little error and to be honest with the exception of getting the ugly warning the thing still functions the way it should. Could someone offer me a little help in cleaning this up a bit? Thanks in advance.

foreach($_POST as $key=>$value) {
	// IF POST VARIABLE NOT BLANK
	if (isset($_POST[$key])) {
		if(get_magic_quotes_gpc()) {
			$_POST[$key] = stripslashes($_POST[$key]);
		}
		// ESCAPE CHARACTERS
		$_POST[$key] = trim(htmlspecialchars(htmlentities(mysql_real_escape_string($_POST[$key]), ENT_QUOTES)));
	}
}

foreach($_GET as $key=>$value) {
	// IF GET VARIABLE NOT BLANK
	if (isset($_GET[$key])) {
		if(get_magic_quotes_gpc()) {
			$_GET[$key] = stripslashes($_GET[$key]);
		}
		// ESCAPE CHARACTERS
		$_GET[$key] = trim(htmlspecialchars(htmlentities(mysql_real_escape_string($_GET[$key]), ENT_QUOTES)));
	}
}


Is This A Good Question/Topic? 0
  • +

Replies To: Warning: stripslashes() expects parameter 1 to be string, array given

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3474
  • View blog
  • Posts: 11,805
  • Joined: 12-December 12

Re: Warning: stripslashes() expects parameter 1 to be string, array given

Posted 09 November 2013 - 12:15 PM

It seems that one or more of the POST-elements are an array. You could use is_array() and then loop through this arrays elements in a similar way.

For these array-elements you could shorten the code:

$_POST[$key] = array_map('stripslashes', $_POST[$key]);

This assumes that these arrays won't also contain arrays [][].
Was This Post Helpful? 1
  • +
  • -

#3 dave_6_10  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 55
  • Joined: 19-March 08

Re: Warning: stripslashes() expects parameter 1 to be string, array given

Posted 09 November 2013 - 02:54 PM

Warning: array_map() [function.array-map]: Argument #2 should be an array in

attempting that throws me this error at log in. perhaps my $_POST is sometimes an array but not always?
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3474
  • View blog
  • Posts: 11,805
  • Joined: 12-December 12

Re: Warning: stripslashes() expects parameter 1 to be string, array given

Posted 09 November 2013 - 03:11 PM

View Postdave_6_10, on 09 November 2013 - 09:54 PM, said:

perhaps my $_POST is sometimes an array but not always?

$_POST is an array, but some of the elements of this array may also be arrays. That is why you need to use is_array().

    // IF POST VARIABLE NOT BLANK
    if (isset($_POST[$key])) {

I would use !empty() for this; if it wasn't set it wouldn't appear in the foreach loop.

empty :the docs
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3474
  • View blog
  • Posts: 11,805
  • Joined: 12-December 12

Re: Warning: stripslashes() expects parameter 1 to be string, array given

Posted 09 November 2013 - 03:17 PM

You also only need to check get_magic_quotes_gpc() once, outside of any loop. It is a configuration setting and will not be changing any time soon. Check it once at the beginning of your code and store the result in a boolean variable ($isMagic).
Was This Post Helpful? 1
  • +
  • -

#6 dave_6_10  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 55
  • Joined: 19-March 08

Re: Warning: stripslashes() expects parameter 1 to be string, array given

Posted 09 November 2013 - 03:32 PM

Something like this?

$connection = mysql_connect("$mysql_server","$mysql_user","$mysql_password") or die ("Unable to connect to MySQL server.");
$db = mysql_select_db("$mysql_database") or die ("Unable to select requested database.");
$isMagic = get_magic_quotes_gpc()
foreach($_POST as $key=>$value) {
	// IF POST VARIABLE NOT BLANK
	if (empty($_POST[$key])) {
		if($isMagic) {
			$_POST[$key] = array($_POST[$key]);
		}
		// ESCAPE CHARACTERS
		$_POST[$key] = trim(htmlspecialchars(htmlentities(mysql_real_escape_string($_POST[$key]), ENT_QUOTES)));
	}
}

foreach($_GET as $key=>$value) {
	// IF GET VARIABLE NOT BLANK
	if (empty($_GET[$key])) {
		if($isMagic) {
			$_GET[$key] = array($_GET[$key]);
		}
		// ESCAPE CHARACTERS
		$_GET[$key] = trim(htmlspecialchars(htmlentities(mysql_real_escape_string($_GET[$key]), ENT_QUOTES)));
	}
}

You have been a fantastic help in this project. Thank you for your timely responses and wonderful feedback. How may I credit you in the credit roll of this project?
Was This Post Helpful? 0
  • +
  • -

#7 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3474
  • View blog
  • Posts: 11,805
  • Joined: 12-December 12

Re: Warning: stripslashes() expects parameter 1 to be string, array given

Posted 09 November 2013 - 03:42 PM

You are welcome. You could click the little green plus sign underneath a post.

Please also note that the mysql extension library is deprecated. See my signature.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1