当我使用xampp时,此代码工作正常,但是当我尝试访问该网站并提交表单时,它只是不起作用!
错误消息是:
警告:mysqli_connect():( HY000 / 2002):无法建立连接 因为目标机器主动拒绝它。在 第4行的H:\ root \ home \ jackboardman-001 \ www \ site1 \ insertjnr.php错误: 无法连接。由于目标,无法建立连接 机器主动拒绝了它。
我已尝试将localhost更改为mysqli.localhost,但这不起作用。
正如我所说,这一切都在本地运作,但不在网上。
以下是代码:
<?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);
?>
答案 0 :(得分:0)
这不是php问题。此问题与服务器相关。 您的服务器没有响应。
请检查服务器响应。
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