...

View Full Version : frustration!!!



cbarlow
05-14-2008, 10:52 PM
so here is my php


<?php
//This is a very simple PHP script that outputs the name of each bit of information (that corresponds to the <code>name</code> attribute for that field) along with the value that was sent with it right in the browser window, and then sends it all to an email address (once you've added it to the script).

if (empty($_POST)) {
print "<p>No data was submitted.</p>";
print "</body></html>";
exit();
}

//Creates function that removes magic escaping, if it's been applied, from values and then removes extra newlines and returns to foil spammers. Thanks Larry Ullman!
function clear_user_input($value) {
if (get_magic_quotes_gpc()) $value=stripslashes($value);
$value= str_replace( "\n", '', trim($value));
$value= str_replace( "\r", '', $value);
return $value;
}


if ($_POST['comments'] == 'Please share any comments you have here') $_POST['comments'] = '';

//Create body of message by cleaning each field and then appending each name and value to it

$body ="Here is the data that was submitted:\n";
$magnetic_thoughts = array( ma01 => "ma01",
ma02 => "ma02",
ma03 => "ma03",
ma04 => "ma04",
ma05 => "ma05",
mb01 => "mb01",
mb03 => "mb03",
mb04 => "mb04",
mb05 => "mb05",
mb06 => "mb06",
mb07 => "mb07",
mc01 => "mc01",
md01 => "md01",
md02 => "md02",
md03 => "md03",
md04 => "md04",
mf01 => "mf01",
mf02 => "mf02",
mh01 => "mh01",
mi01 => "mi01",
mi02 => "mi02",
mi03 => "mi03",
mi04 => "mi04",
mj01 => "mj01",
mk01 => "mk01",
ml01 => "ml01",
ml02 => "ml02",
ml03 => "ml03",
ml04 => "ml04",
ml05 => "ml05",
ml06 => "ml06",
ml07 => "ml07",
ml08 => "ml08",
ml09 => "ml09",
ml10 => "ml10",
ml11 => "ml11",
mm01 => "mm01",
mn01 => "mn01",
mn02 => "mn02",
mp01 => "mp01",
mp02 => "mp02",
mr01 => "mr01",
ms01 => "ms01",
ms02 => "ms02",
ms03 => "ms03",
mt01 => "mt01",
mt02 => "mt02",
mt03 => "mt03",
mt04 => "mt04",
mt05 => "mt05",
mt06 => "mt06",
mt07 => "mt07",
mw02 => "mw02",
mw03 => "mw03",
mw04 => "mw04",
my01 => "my01",
my02 => "my02",
my03 => "my03",
my04 => "my04",
my05 => "my05",
my06 => "my06",
);


$magnetic_thoughts = $_POST["magnetic_thoughts"];

if (is_array($magnetic_thoughts)) {
foreach ($magnetic_thoughts as $key => $value) {
print "ordering these $value magnetic thoughts.<br>";
}
}

foreach ($_POST as $key => $value) {
$key = clear_user_input($key);
$value = clear_user_input($value);
if ($key=='extras') {

if (is_array($_POST['extras']) ){
$body .= "$key: ";
$counter =1;
foreach ($_POST['extras'] as $value) {
//Add comma and space until last element
if (sizeof($_POST['extras']) == $counter) {
$body .= "$value\n";
break;}
else {
$body .= "$value, ";
$counter += 1;
}
}
} else {
$body .= "$key: $value\n";
}
} else {

$body .= "$key: $value\n";
}
}

extract($_POST);
//removes newlines and returns from $email and $name so they can't smuggle extra email addresses for spammers
$email = clear_user_input($email);
$name = clear_user_input($name);

//Create header that puts email in From box along with name in parentheses and sends bcc to alternate address
$from='From: '. $email . "(" . $name . ")" . "\r\n" . 'Bcc: ceri@bcwineguys.com' . "\r\n";


//Creates intelligible subject line that also shows me where it came from
$subject = 'product order from web site';

//Sends mail to me, with elements created above
mail ('ceri@bcwineguys.com.com', $subject, $body, $from);


?>


everything works except when the email order comes to my inbox it says:


Here is the data that was submitted:
name:
address:
phone_number:
city:
prov/state:
email:
magnetic_thoughts: Array

why does the order not come to my email. the selected checkboxes don't return any info.

help!!!!!

PappaJohn
05-14-2008, 11:20 PM
I don't see where you're getting $_POST['magnetic_thoughts'], but presumably it's from an array of checkboxes.

In that case,


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

is doing it's job. It's pulling the $key as 'magnetic_thoughts' and the $value as Array - which is what it is.

cbarlow
05-14-2008, 11:30 PM
ok so do you mean that i should replace this line


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


with the one you suggested or should i ADD that line.

PappaJohn
05-14-2008, 11:37 PM
I didn't suggest any code, the line I posted was taken from your code.



foreach ($_POST as $key => $value) {
$key = clear_user_input($key);
$value = clear_user_input($value);
if ($key=='extras') {

if (is_array($_POST['extras']) ){
$body .= "$key: ";
$counter =1;
foreach ($_POST['extras'] as $value) {
//Add comma and space until last element
if (sizeof($_POST['extras']) == $counter) {
$body .= "$value\n";
break;}
else {
$body .= "$value, ";
$counter += 1;
}
}
} else {
$body .= "$key: $value\n";
}
} else {

$body .= "$key: $value\n";
}
}


What I'm saying, is the output you are getting is exactly what the above code is doing.

If, the magnetic_thoughts are coming from an array of checkboxes (which you didn't bother to address), and you want the values to be displaying in your email, you are going to have to loop through the magnetic_thoughts array, parse each value and add it to your $body

BTW, in this code:


$magnetic_thoughts = array( ma01 => "ma01",
ma02 => "ma02",
ma03 => "ma03",
ma04 => "ma04",
ma05 => "ma05",
mb01 => "mb01",
mb03 => "mb03",
mb04 => "mb04",
mb05 => "mb05",
mb06 => "mb06",
mb07 => "mb07",
mc01 => "mc01",
md01 => "md01",
md02 => "md02",
md03 => "md03",
md04 => "md04",
mf01 => "mf01",
mf02 => "mf02",
mh01 => "mh01",
mi01 => "mi01",
mi02 => "mi02",
mi03 => "mi03",
mi04 => "mi04",
mj01 => "mj01",
mk01 => "mk01",
ml01 => "ml01",
ml02 => "ml02",
ml03 => "ml03",
ml04 => "ml04",
ml05 => "ml05",
ml06 => "ml06",
ml07 => "ml07",
ml08 => "ml08",
ml09 => "ml09",
ml10 => "ml10",
ml11 => "ml11",
mm01 => "mm01",
mn01 => "mn01",
mn02 => "mn02",
mp01 => "mp01",
mp02 => "mp02",
mr01 => "mr01",
ms01 => "ms01",
ms02 => "ms02",
ms03 => "ms03",
mt01 => "mt01",
mt02 => "mt02",
mt03 => "mt03",
mt04 => "mt04",
mt05 => "mt05",
mt06 => "mt06",
mt07 => "mt07",
mw02 => "mw02",
mw03 => "mw03",
mw04 => "mw04",
my01 => "my01",
my02 => "my02",
my03 => "my03",
my04 => "my04",
my05 => "my05",
my06 => "my06",
);


$magnetic_thoughts = $_POST["magnetic_thoughts"];

The line $magnetic_thoughts = $_POST["magnetic_thoughts"]; is overwriting the array you created immediately before it.

cbarlow
05-14-2008, 11:44 PM
thankyou for helping me, i'm sorry if this is just me being totally inexperienced.

how do i address the array of checkboxes, and where should i be putting the array?

i am using a combination of code from a book and from a class.

i am so stuck

PappaJohn
05-14-2008, 11:53 PM
$magnetic_thoughts = $_POST["magnetic_thoughts"]; will get the array of checkboxes ie: $magnetic_thoughts will be an array of the values.

Inside the loop where you build your $body you will need to loop through the $magnetic_thoughts array.

I understand inexperience, but I do not agree with simply copying / pasting code which you do not understand. Based on your questions, I strongly suspect you don't understand what the code is doing.

I suggest you do some research and figure out what the code you posted is doing. Then, you can figure out how to accomplish what I posted above. Otherwise, simply posting working code for you to copy/paste is not helping you, and will only cause more problems later.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum