1

How do I duplicate form boxes and the codes in my php to "grab the newly added form boxes"? I'm planning to create 4 form boxes (email, password, contact, Bio) but I'm already stuck on the second one. codes:

<form action="#" method="post">
 <input type="text" name="email" class="emailSubmitSidebar" placeholder=" Your Email">
 <input type="text" name="password" class="password" placeholder="Password">
 <input type="submit" name="submit" class="submitButton">
</form>

<?php
if(isset($_POST["submit"]))
{

$fileHandle = fopen('info.txt', 'w+')
        OR die ("Can't open file\n");
$email=$_POST["email"];
$password=$_POST["password"];
$result = fwrite ($fileHandle, $email, $password);
if ($result)
     {
         print '<script type="text/javascript">'; 
         print 'alert("Email added!")'; 
         print '</script>';  
    } else {
        print '<script type="text/javascript">'; 
        print 'alert("Email not added!")'; 
        print '</script>';  
    };
fclose($fileHandle);
}
?>

PHP code keeps failing, direct fix for this?

Alex
  • 8,461
  • 6
  • 37
  • 49
Gio Andrey
  • 11
  • 2
  • Possible duplicate of [PHP write file from input to txt](http://stackoverflow.com/questions/14998961/php-write-file-from-input-to-txt) – user2925795 Dec 23 '15 at 16:23
  • fwrite takes three parameters, but the last one is the length and is optional. you need to concat the second and third parameters like in framos' answer – I wrestled a bear once. Dec 23 '15 at 16:36

1 Answers1

0

Change this line:

$result = fwrite ($fileHandle, $email."-".$password);

fwrite takes a single string a parameter, you can't pass two parameters

Ram
  • 3,092
  • 10
  • 40
  • 56
framos
  • 21
  • your explanation is wrong, yet your answer is correct and contradicts the explanation... – I wrestled a bear once. Dec 23 '15 at 16:33
  • @Pamblam. I don't agree with your severe judgment: his explanation is not _wrong_ but only clumsy. First because of "single string a parameter" instead of "single string parameter". Then and above all because when he says "you can't pass two parameters" he's talking about the _query parameters_ that the OP wants to write. So I upvote to compensate. – cFreed Dec 24 '15 at 00:16
  • severe judgement? i upvoted when i wrote that. i acknowledged it is the correct answer.. – I wrestled a bear once. Dec 24 '15 at 04:14