In order to save user input data using PHP, you can utilize a method where the data is written to a file in an array format. Let's demonstrate this with an example scenario. Imagine a scenario where you have a button labeled "ClickBtn" along with two input fields named "Password" and "Username". The goal is to store any information entered into these fields into an array whenever the button "ClickBtn" is clicked. Below is an illustration of how the HTML code would look:
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <!-- You can choose a preferred version of JQuery here -->
<script>
function SaveToFile(){
var Username = document.getElementById("Username").value;
var PWord = document.getElementById("Password").value;
function GetFileCount(pword){
$.ajax({async: false,
type: 'GET',
url: 'SaveToDatabase.php?v=' + pword + '&uname=' + Username,
success: function(data) {
console.log(data); // Actions to perform when PHP responds with data
}
});
}
}
</script>
<input id="Username" placeholder="Username"></input>
<input id="Password" placeholder="Password"></input>
<button onclick="">Save</button>
</html>
Now that we have a functional script, the next step is to create a PHP script that can save the data provided. A possible PHP script implementation could resemble the following (utilizing $_GET["v"] for the Password and $_GET["uname"] for the Username):
<?php
$path = __DIR__ . '/OurDataBase/MainArrayFile.txt';
$pword = $_GET['v'];
$uname = $_GET['uname'];
if(file_exists($path)){
$curarray = file_get_contents($path);
} else {
$curarray = array();
}
$curarray[$uname] = $pword;
echo $curarray;
?>
Customize the code according to your requirements and preferences. Have a productive time logging passwords!
PS: Apologies if there was any confusion, I appreciate your patience.