Author Topic: PHP/Javascript problem - Still need help :c  (Read 888 times)

I need to know how to take the value of a javascript variable and set it to the value of a php variable, so I can write it to a file. Can anyone help me with this?
This doesn't go in coding help, that's TS problems only.

EDIT: First problem is gone, now I need to know how to run a php script on my webpage
« Last Edit: November 29, 2011, 09:52:01 PM by mp7964 »

Ah i can help, whats your problem?

Ah i can help, whats your problem?
is the title the only thing you read

Code: [Select]
<?php

$file 
"file.txt";

$openit fopen($file'w');

$content "Something\n";

fwrite($openit,$content);

fclose($openit);

// there

?>

« Last Edit: November 29, 2011, 08:50:22 PM by clinr121 »

Code: [Select]
<?php

$file 
"file.txt";

$openit fopen($file'w');

// do some code i think

?>


Yeah, but I need it to get a variable from a Javascript code to write to the file.


Read my post again, i think i understand.

That only opens the file. It doesn't write anything, for one. I just need it to write the value of the variable $input to file.txt


Needs 2 steps in PHP

I figured that much out, I just don't know what to do.

Instead of opening files and such you could just use GET or something of the like to send variables to a PHP script. Depends on what you're trying to do though.
Edit: Oh, you might have already got your answer. Sorry if I'm misunderstanding you. Or maybe I misread. forget I don't know. I'm going to bed.
« Last Edit: November 29, 2011, 09:04:00 PM by Dropshock »

Something like this maybe?

Javascript:
Code: [Select]
window.location = "http://www.yourdomain.com/yourpage.php?yourVar=" + yourVar;PHP:
Code: [Select]
<?php
$file 
fopen("file.txt",'w');
fwrite($file,$_GET["yourVar"]);
fclose($file);
?>


Only started learning PHP a week ago so this could easily be wrong or there could be better ways
« Last Edit: November 29, 2011, 09:13:54 PM by Headcrab Zombie »

Something like this maybe?

Javascript:
Code: [Select]
window.location = "http://www.yourdomain.com/yourpage.php?yourVar=" + yourVar;PHP:
Code: [Select]
<?php
$file 
fopen("file.txt",'w');
fwrite($file,$_GET["yourVar"]);
fclose($file);
?>


Only started learning PHP a week ago so this could easily be wrong or there could be better ways


This should do, but now I need to know how to call the php script directly from an HTML page. Using javascript to run it would be fine, though, but I'd to know how.

Bump cause I still need help.

I need to know how to call the php script directly from an HTML page. Using javascript to run it would be fine, though, but I'd to know how.