gpt4 book ai didi

php - 无法通过 socket 问题连接到本地 MySQL 服务器

转载 作者:行者123 更新时间:2023-11-29 00:38:49 26 4
gpt4 key购买 nike

我正在使用 php 创建联系表单。当我填写所有内容并按提交时,它不会向特定电子邮件地址发送任何消息。它显示了几个错误消息。

错误信息:

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Can't connect 
to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /homez.91
/maaks/www/hotel/eng/resellers.php on line 93

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the
server could not be established in /homez.91/maaks/www/hotel/eng/resellers.php on line
93

etc.....

PHP 代码:

<?php
if(isset($_POST['Send']) && $_POST['Send'] == "Submit")
{
$fname = mysql_real_escape_string($_POST['fname']);
$email = mysql_real_escape_string($_POST['email']);
$conum = mysql_real_escape_string($_POST['conum']);
$country = mysql_real_escape_string($_POST['country']);
$find = mysql_real_escape_string($_POST['find']);
$msg = mysql_real_escape_string($_POST['msg']);

$err = array();


if(isset($fname) & isset($email) & isset($conum) & isset($country) & isset($find) &
isset($msg))
{

if(empty($fname) & empty($email) & empty($conum) & empty($country) & empty($find) &
empty($msg))
{
$err[] = "All field require";
}
else
{
if(empty($fname))
$err[] = "Your first name require";
}

}
else
{
if(!empty($err))
{
foreach($err as $er)
{
echo "<font color=red>$er</font><br/>";
}
}
else
{
$to = "creativeart09@yahoo.com";
$subject = "Message from Customer";
$message = "$msg";
$from = "$email";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);

if(mail())
{

echo "<script>";
header("Refresh: 0; url=Thankyou.html");
echo "</script>";
}
else
{
echo "Something is wrong" . mysql_error();
}
}
}

}

?>

我的代码有什么问题?

最佳答案

在使用 mysql_real_escape_string 函数之前,您必须连接到您的 mysql 数据库。此外,mysql_* 在 php 中已弃用,您应该使用 mysqli 或 pdo 进行数据库工作。

此外,mysql_real_escape_string 旨在保护 mysql 数据库免受注入(inject)尝试,但您只是发送电子邮件。

关于php - 无法通过 socket 问题连接到本地 MySQL 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13189247/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com