LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-06-2007, 10:04 AM   #1
crashovaride
LQ Newbie
 
Registered: Jul 2005
Location: New York
Posts: 6

Rep: Reputation: 0
PHP Variable help?


[Solved] by darkhack

Last edited by crashovaride; 11-23-2008 at 12:51 PM.
 
Old 11-06-2007, 12:18 PM   #2
Darkhack
Member
 
Registered: Mar 2005
Location: Kansas City
Distribution: Ubuntu 7.10
Posts: 47

Rep: Reputation: 15
I think the scope of $datainfo isn't set properly. You are initializing it inside a foreach loop which means that it is being recreated on each loop. Try this instead.

Code:
// Initialize variable outside foreach scope.
$datainfo = "";
foreach ($_POST as $field => $value)
{
    echo "<font color='white'>$field = $value<br></font>";
    /* Notice the dot equals (.=) sign which appends data to a variable.
     * With this, we don't need to add it again to the end of the statement. */
    $datainfo .= $field => $value . "<br>";
}
 
Old 11-06-2007, 12:40 PM   #3
crashovaride
LQ Newbie
 
Registered: Jul 2005
Location: New York
Posts: 6

Original Poster
Rep: Reputation: 0
Thank you for the quick reply, however, when using the code you have provided (and thank you for pointing this out to me.) It seems to error on the line with the following code:unexpected T_DOUBLE_ARROW I apologize for being a bother. This is my first time writing php scripts. The code i'm using is:

$datainfo = "";

foreach ($_POST as $field => $value)
{
echo "<font color='white'>$field = $value<br></font>";
/* Notice the dot equals (.=) sign which appends data to a variable.
* With this, we don't need to add it again to the end of the statement. */
$datainfo .= $field=>$value . "<br>"; */it's erroring on this line. Any suggestions?
}

Thank you for the help.
 
Old 11-06-2007, 12:43 PM   #4
brazilnut
Member
 
Registered: Nov 2007
Posts: 113

Rep: Reputation: 16
Code:
$datainfo .= $field.": ".$value . "<br>";
It's already been split into it's constituent parts
 
Old 11-06-2007, 12:47 PM   #5
crashovaride
LQ Newbie
 
Registered: Jul 2005
Location: New York
Posts: 6

Original Poster
Rep: Reputation: 0
Thank you for the code Brazilnut it's working great now. Also, thank you DarkHack for pointing me in the right direction. Much appreciated.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP extension_dir variable retrovertigo Programming 2 08-13-2007 02:05 PM
php unicode global variable jayakrishnan Programming 1 03-10-2006 04:19 PM
PHP: object to variable carlosruiz Programming 2 07-01-2005 11:09 AM
PHP Variable = function? wh33t Programming 2 01-22-2005 06:28 AM
# URL variable in PHP fatman Programming 1 06-04-2004 10:42 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration