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);
?>