Jump to content

Quick question


fieldy920

Recommended Posts

I am by no means an expert at this, but the following does not work:

 

$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

 

It is part of a larger script, however the script stops working directly at the end of "$a =>".

It instead decides to print the rest of the script ($b and onwards) in the browser window.  Is there anything else I need to be aware of or do you need me to post the entire script?

Link to comment
https://forums.phpfreaks.com/topic/141813-quick-question/
Share on other sites

That is the correct syntax...

$body = "We have received the following information:\n\n"; 
foreach($fields as $a => $b)
{ 
$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]);
}

 

The only thing I can think of, would be to put single quotes around $a in the $_REQUEST... but the script shouldnt print itself (you are saying it's printing the code, correct?)

Link to comment
https://forums.phpfreaks.com/topic/141813-quick-question/#findComment-742464
Share on other sites

Okay, if you take out that loop - does it do anything odd?

 

Like this:

<?php
$body = "We have received the following information:\n\n"; 
/*foreach($fields as $a => $b)
{ 
$body .= sprintf("%20s: %s\n",$b,$_REQUEST['$a']);
}*/
?>

 

And that works okay?

 

if so, can you print_f($fields)?

Link to comment
https://forums.phpfreaks.com/topic/141813-quick-question/#findComment-742480
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.