Home » Php » php – Connect Error(2002)Connection refused (Heroku)

php – Connect Error(2002)Connection refused (Heroku)

Posted by: admin February 25, 2020 Leave a comment

Questions:

I have been trying to connect to my database (I used Xampp) and made a PHP trying to link the file to the “users” database that I made. There is an issue as whenever I click the “Register” button it has an error saying “Connect Error(2002)Connection refused.” Any help would be appreciated!

PHP code

<?php

$name = $_POST['name'];
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$phone = $_POST['phone'];

if (!empty($name) || !empty($username) || !empty($password) || !empty($email) || !empty($phone)) {

    $host = "localhost:80";
    $dbUsername = "root";
    $dbPassword = "";
    $dbname = "pracdata";


    //create connection
    $conn = new mysqli($host, $dbUsername, $dbPassword, $dbname);
    if (mysqli_connect_error()) {
     die('Connect Error('. mysqli_connect_errno().')'. mysqli_connect_error());
    } else {
     $SELECT = "SELECT email From users Where email = ? Limit 1";
     $INSERT = "INSERT Into users (name, username, password, email, phone) values(?, ?, ?, ?)";


     //Prepare statement
     $stmt = $conn->prepare($SELECT);
     $stmt->bind_param("s", $email);
     $stmt->execute();
     $stmt->bind_result($email);
     $stmt->store_result();
     $rnum = $stmt->num_rows;

     if ($rnum==0) {
      $stmt->close();
      $stmt = $conn->prepare($INSERT);
      $stmt->bind_param("ssssii", $username, $username, $password, $email, $phone);

      $stmt->execute();
      echo "Your account has been registered!";
     } else {
      echo "This email is already linked to Preak account";
     }
     $stmt->close();
     $conn->close();
    }
} else {
 echo "All fields are required";
 die();
}
?>
How to&Answers: