PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Wed Oct 16, 2019 3:16 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 37 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject:
PostPosted: Wed Mar 28, 2007 8:43 am 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
At some point $_POST['marketsource'] was converted to a string directly from an array, thus resulting in the string "Array." Trace the variable backward to find the culprit.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 28, 2007 9:37 am 
Offline
Breakbeat Nuttzer
User avatar

Joined: Wed Mar 24, 2004 8:57 am
Posts: 13098
Location: Melbourne, Australia
What feyd said ;) You're overwriting $_POST["marketsource"] somewhere.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 28, 2007 12:00 pm 
Offline
Forum Newbie

Joined: Thu Feb 01, 2007 9:17 am
Posts: 15
Thank you both for the response. I scoured the code and simply do not see where it could be.

In the first 50 lines, it only appears once as seen below. (In fact, it only appears once in the entire script until the HTML dump/email body creation.)

Syntax: [ Download ] [ Hide ]
<?php



/** 1 **/

session_start();



/** 2 **/

//See if evil magic_quotes is enabled, and fix problems if it is

$quotes_on = (get_magic_quotes_gpc() || get_magic_quotes_runtime());

if ($quotes_on)

{

    foreach ($_POST as $key => $value)

    {

        $_POST[$key] = stripslashes($value);

    }

}



/** 3 **/

$_SESSION["post"] = $_POST;



/** 4 **/

//Load in the required Swift files

require_once "classes/Swift.php";

require_once "classes/Swift/Connection/SMTP.php";



/** 5 **/

//Create an empty array where we can catch any fields which were not filled in

$fields_not_set = array();



//FOR EACH REQUIRED FIELD

//Check if all POST data was sent, redirect with an error if not

if (empty($_POST["Name"])) $fields_not_set[] = "Name";

if (empty($_POST["Email"])) $fields_not_set[] = "Email";

//if (empty($_POST["subject"])) $fields_not_set[] = "subject";

//if (empty($_POST["comments"])) $fields_not_set[] = "comments";



//If $fields_not_set contains any values, then something wasn't filled in. Time to redirect.

if (!empty($fields_not_set))

{

    //Read further down to see how we'll modify form.php to handle the error

    header("Location: contact_us.php?error=incomplete&fields=" . implode(",", $fields_not_set));

    exit();

}



//Copy the POST data to standard globals

$name = $_POST["Name"];

$email = $_POST["Email"];

$address = $_POST["Addy"];

$citystatezip = $_POST["CSZ"];

$entitytype = $_POST["entitytype"];

//var_dump($_POST["marketsource"]);

$marketsource = implode(", ", $_POST['marketsource']);


If there is a conflict here, perhaps you can show me the error of my ways? Or, if not, perhaps you can point me elsewhere to look? Either way I appreciate the help learning.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 28, 2007 12:41 pm 
Offline
Breakbeat Nuttzer
User avatar

Joined: Wed Mar 24, 2004 8:57 am
Posts: 13098
Location: Melbourne, Australia
I'll give a hint:

Syntax: [ Download ] [ Hide ]
if ($quotes_on)

{

    foreach ($_POST as $key => $value)

    {

        $_POST[$key] = stripslashes($value);

    }

}


What's $_POST["marketsource"]? An array. What happens when you pass that array to stripslashes() ? ;)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 28, 2007 2:18 pm 
Offline
Forum Newbie

Joined: Thu Feb 01, 2007 9:17 am
Posts: 15


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 28, 2007 3:51 pm 
Offline
Breakbeat Nuttzer
User avatar

Joined: Wed Mar 24, 2004 8:57 am
Posts: 13098
Location: Melbourne, Australia
Glad you got it sorted. To answer the question about why you get "Array" when passing an array to stripslashes(). stripslashes() expects a string, so by context, whatever you pass it will be turned into a string. If you turn an array into a string (this is called "casting" or "type-casting") PHP just makes the string "Array". stripslashes() was casting your array as a string (Array) then trying to take out \ from it before returning it, thus returning "Array". Because you then write that value back into $_POST["marketsource"], you replace the original array with a string.

Your solution will work well for your current version, but then what happens if you have an array inside another array. It only works up to two levels deep. I wouldn't stress over the solution but you may want to have a think about a (scalable) workaround for deeper nesting levels if you get bored ;)


Top
 Profile  
 
PostPosted: Sun Jul 06, 2014 1:56 pm 
Offline
Forum Newbie

Joined: Sun Jul 06, 2014 1:48 pm
Posts: 1


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 37 posts ]  Go to page Previous  1, 2, 3

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group