title: Cant connect to localhost databse Error: Failed to connect: A connection could not be established because the destination computer actively refused it
body: <p>Im trying to get my database for my local host up and running using MYSQLI and i get the message
  &quot;Failed to connect: A connection could not be established because the destination computer actively refused it&quot;</p>
  <p>My code is the following</p>
  <p>the connect page called connect.php</p>
  <pre><code>&lt;?php
  require_once &quot;user_db.php&quot;;
  
  $mysqli = mysqli_connect($servername,$username,$password,$database);
  
  if (mysqli_connect_errno()) {
    echo &quot;Failed to connect:&quot;,mysqli_connect_error();
  }
  
  function performQuery($sql) {
    global $mysqli;
    $result = mysqli_query($mysqli,$sql);
    if ($result) {
      return $result;
    } else {
      echo &quot;Something went wrong&quot;;
    }
  }
   ?&gt;
  </code></pre>
  <p>and in adition to that i have the user_db.php page with my database information</p>
  <pre><code>   &lt;?php
  $servername = &quot;localhost&quot;;
  $username = &quot;root&quot;;
  $password = &quot;12345&quot;;
  $database = &quot;recovery&quot;
   ?&gt;
  </code></pre>
  <p>and then the page where i try to add stuff to my database</p>
  <pre><code>    &lt;?php
  require_once &quot;DB_handling/connect.php&quot;;
  
  if(isset($_POST[&quot;submit&quot;])) {
    $duration = $_POST['TD'];
    $intensity  = $_POST['TI'];
    $RPE = $TI*$TD;
  
  
  $New = performQuery(&quot;INSERT INTO rpe(duration, intensity, rpe) VALUES ('$duration', '$intensity', '$RPE')&quot;);
  }
   ?&gt;
  </code></pre>
  <p>with a simple form field to get the values</p>
  <pre><code>    &lt;form class=&quot;&quot; action=&quot;insert.php&quot; method=&quot;post&quot;&gt;
  Training Intensity
  &lt;input type=&quot;number&quot; placeholder=&quot;1-10&quot; name=&quot;TI&quot;&gt;
  &lt;br&gt;
  Training Duration
  &lt;input type=&quot;number&quot; placeholder=&quot;in minutes&quot; name=&quot;TD&quot;&gt;
  &lt;br&gt;
  &lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit&quot;&gt;
  &lt;/form&gt;
  </code></pre>
  <p>Im using MAMP as my localhost server</p>
  <p>Does know how to fix the problem. Thanks in advance</p>