No connection could be made because the target machine actively refused it.

Hello! I came across the following problem while trying to connect to my MySQL database through PHP running on a web server. It is the code for a small social networking site (the sign up page). There are two problems. Port is 3306.

This is the PHP Code:
[php]<?php
$dbc = mysql_connect(‘host_name’, ‘DB_USERNAME’, ‘DB_PASSWORD’, ‘DB_NAME’);

$username = $_POST[‘new_username’];
$password = $_POST[‘new_password’];
$password_re = $_POST[‘new_password_re’];
$house = $_POST[‘house’];
$gender = $_POST[‘gender’];

if(!empty($username) && !empty($password) && !empty($password_re) && !empty($house) && !empty($gender) && ($password == $password_re)) {
//To make sure some one else is not using the same username
$query = “SELECT * FROM tablename WHERE username = $username”;
$data = mysqli_query($dbc, $query);
if(mysqli_num_rows($data) == 0)
{
$query = “INSERT INTO login (username, password, joindate)” .
“VALUES (’$username’, SHA(’$password’), NOW())”;
mysqli_query($dbc, $query);
}
else
{
echo"

Sorry, an account already exists with this username, please select a new one.

";
}
}
else
{
echo"

All fields are mandatory or compulsory.";
}
mysqli_close($dbc);
?>[/php]

This is the error I get after trying to run it on a server:

Warning: mysql_connect(): [2002] No connection could be made because the target machine actively refused it. (trying to connect via tcp://[i]webhost.com[/i].in:3306) in D:\WEBDATA\[i]webhost.com[/i]\new_user.php on line 3 Warning: mysql_connect(): No connection could be made because the target machine actively refused it. in D:\WEBDATA\[i]webhost.com[/i]\new_user.php on line 3 All fields are mandatory or compulsory. Warning: mysqli_close() expects parameter 1 to be mysqli, boolean given in D:\WEBDATA\[i]webhost.com[/i]\new_user.php on line 30

PROBLEMS:

  1. I can’t connect to my MySQL database through PHP (can connect through PHPmyAdmin)
  2. I dont understand what Warning: mysqli_close() expects parameter 1 to be mysqli.

Please help me out for I am a newbie to PHP & MySQL.

Thanks in advance! :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service