So i got 3 files: 1) test.php is the main page that is passing the datas to anotherTest.php;
<script>
$(document).ready(function(){
$("#button").click(function(){
var server = $("#server").val();
var username = $("#username").val();
var password = $("#password").val();
var dataString= 'server=' + server + '&username=' + username + '&password=' + password;
if(server == '' || username == '')
{
alert("Please Complete All Fields Correctly");
}else {
$.ajax({
type: "POST",
url: "anotherTest.php",
data: dataString,
cache: false,
success: function(result){
if(result==1)
{
alert("we couldn't form a connection");
}else if(result==2){
alert("The connection is already up");
}else {
$("#prepend").prepend(result);
}
}
});
}
return false;
});
});
</script>
2)Class.php where i got my clases and function and the array declared;
$arr=array();
3)anotherTest.php where i want to test if i can make a connection, the connection is not already stored, and if so, to store the new connection in array;
$server = $_POST['server'];
$username = $_POST['username'];
$password = $_POST['password'];
if (@mysqli_connect($server, $username, $password, "")==FALSE)
{
echo "1";
}else if(array_key_exists($server.$username, $arr)){
echo "2";
}else {
$arr[$server.$username] = new Conn($server, $username, $password, "");
echo "<button class=button>" . $arr[$server.$username]->toString() . "</button>";
}
Again my problem is that every time i am pressing the button that triggers all of that, the array from class.php start from empty. Any advice?