0

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?

1 Answers1

-1

It's not easy to see how Class.php is being used here? It starts empty as that's how you define it. Are you trying to populate it with your data?

I'd massively recommend xdebug if you're just starting out, as you can step through each line of code and see what is happening :) took me about 13 years to do so, I've never looked back...

cook2909
  • 1
  • 1
  • Thanks for offering a suggestion, but this may have been more appropriate as a comment because it does not fully answer the question. – Run_Script May 03 '20 at 14:10