0

This code works fine when I use xampp but when I try go to the site and submit a form it just doesn't work!

The error message is:

Warning: mysqli_connect(): (HY000/2002): No connection could be made because the target machine actively refused it. in H:\root\home\jackboardman-001\www\site1\insertjnr.php on line 4 ERROR: Could not connect. No connection could be made because the target machine actively refused it.

I've tried changing the localhost to mysqli.localhost but this won't work.

As I've said it all works locally but not on the web.

Here's the code:

<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "root", "correctpassword", "jnrcampers");

// Check connection
if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}

// Escape user inputs for security
$first = mysqli_real_escape_string($link, $_REQUEST['first']);
$last = mysqli_real_escape_string($link, $_REQUEST['last']);
$email = mysqli_real_escape_string($link, $_REQUEST['email']);
$mobile = mysqli_real_escape_string($link, $_REQUEST['mobile']);
$address = mysqli_real_escape_string($link, $_REQUEST['address']);
$comments = mysqli_real_escape_string($link, $_REQUEST['comments']);

// attempt insert query execution
$sql = "INSERT INTO customers (first, last, email, mobile, address, comments) VALUES ('$first', '$last', '$email', '$mobile', '$address','$comments')";
if(mysqli_query($link, $sql)){
    echo "Thank";
} else{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
 header("Location: end.html");
exit;
// close connection
mysqli_close($link);
?>
halfer
  • 19,824
  • 17
  • 99
  • 186
  • 1
    thats the problem of online server. check if the port is open or not to access db from an application – Exprator May 15 '17 at 11:35
  • error is pretty self explanatory. database is down – Peter May 15 '17 at 11:36
  • We generally discourage the posting of links to websites that are experiencing problems, since if the question relies upon that link and the problem is fixed, the question may become useless for future readers. [This discussed is related](https://meta.stackoverflow.com/questions/254428/something-in-my-web-site-or-project-doesnt-work-can-i-just-paste-a-link-to-it). Thankfully in this case, the link can just be removed. – halfer May 16 '17 at 12:47

1 Answers1

0

it's not php issue. This problem is server related issue. your Server is not responding.

Please check the server response.

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

#2002 - No connection could be made because the target machine actively refused it

Community
  • 1
  • 1