0

I am trying to make this php function get called on a press of a button (create).

<?php
$myfile = fopen("details.txt", "a") or die("Unable to open file!");
$txt = "John Smith\n";
fwrite($myfile, $txt);
$pwd = "123456\n";
fwrite($myfile, $pwd);
fclose($myfile);
?>

I tried this in JS: function Create(){

<?php
$myfile = fopen("Details.txt", "a") or die("Unable to open file!");
$txt = "John Smith\n";
fwrite($myfile, $txt);
$pwd = "123456\n";
fwrite($myfile, $pwd);
fclose($myfile);
?>

}

and this in html

<form name="userForm" onsubmit="return validateForm()" >

                 Enter your name:<br> <input type="text" name="name" id="name"> <br>
                Enter your password: <br><input type ="password" name="password"                         id="password">

                <br>
                <button type="submit" onclick=" return validateForm()">Login</button>
                 <br>
                <button type="submit" onclick="Create()">Create</button>
            </form>
George
  • 25
  • 6
  • 3
    what you want is impossible. php runs on the server, and it will be executed and COMPLETED long before the page ever reaches the client, where the JS executes. you need to use AJAX – Marc B Nov 02 '15 at 20:06
  • since its just a form, why not do it the 'usual' way. submit form, on submit process wit h php –  Nov 02 '15 at 20:07

0 Answers0