Jump to content

[SOLVED] request for help writing $_SERVER["REMOTE_ADDR"] as part of an fwrite


marionreview

Recommended Posts

Hi- New to the forum.  Please pardon mistakes.

 

I have a form that creates the variables r1, r2, r3 as part of a very simple HTML form.  The form then calls a php page that does the following:

 

<?php

$myfile = fopen ("outcomes_survey.csv", "a");

$fp = fwrite($myfile,date("Y/m/d").",$_SERVER["REMOTE_ADDR"],$_POST[r1],$_POST[r2],$_POST[r3]

");

fclose($myfile);

?>

 

If I take out the code

 

,$_SERVER["REMOTE_ADDR"]

 

the code works perfectly and write the date and variables to outcomes_survey.csv

 

Can anyone tell me how to fix my code so that it will write the user's IP address?  I assume I have a simple syntax error.  I have tried using single quotes. 

 

Thanks a lot.

When using arrays in strings who's indexes are also surrounded by quotes you must use curly braces ({ }) to tell PHP where the variable starts and ends.

 

$fp = fwrite($myfile,date("Y/m/d").",{$_SERVER["REMOTE_ADDR"]},$_POST[r1],$_POST[r2],$_POST[r3]
");

 

In the future you should use [code] or [php] tags, it makes things easier to read.

When using arrays in strings who's indexes are also surrounded by quotes you must use curly braces ({ }) to tell PHP where the variable starts and ends.

 

 

and in php6 {} will be the [] square braces i think?

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.