Jump to content

Recommended Posts

Hey guys!

 

Im having trouble sending variables to another php file. This is the code for the php file that sends the data:

 

$number=2;

$number2=3;

header('Location:http://mysite.com/get.php?num=$number&num2=$number2');

 

the receiving file, get.php, is meant to receive the value of $number and ouput it to a .txt file. The code is:

 

$digit = $_GET["num"];

$digit2 = $_GET["num2"];

$log = fopen("log.txt", "a");

fwrite($log, $digit."\n");

fwrite($log, $digit2."\n");

fclose($log);

 

but all the log file contains is:

 

$number

$number2

 

When what I want to be seeing is:

 

2

3

 

Im guessing this comes down to how I've passed the variables in the sending file to the receiving file. Can anyone please tell me what I have to change? Thanks very much for any help given!

 

it's because you are using single quotes instead of double quotes in your header function call. Single quotes interprets the variable names literally. If you want php to look at the variables as variables, use double quotes

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.