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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.