Author Topic: No connection could be made because the target machine actively refused it.  (Read 349 times)

Advait

  • Guest
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 Code: [Select]
<?php
$dbc 
mysql_connect('[i]host_name[/i]''[i]DB_USERNAME[/i]''[i]DB_PASSWORD[/i]''[i]DB_NAME[/i]');

$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 [i]tablename[/i] 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
"<p>Sorry, an account already exists with this username, please select a new one.</p>";
}
}
else
{
    echo
"<p>All fields are mandatory or compulsory.";
}
mysqli_close($dbc);
?>


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

Code: [Select]
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
Code: [Select]
Warning: mysqli_close() expects parameter 1 to be mysqli.

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

Thanks in advance! :)