1

我正在用 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();
                    }
                }
            }

        }           

 ?>

我的代码有什么问题?

4

1 回答 1

1

您必须先连接到您的 mysql 数据库,然后才能使用该mysql_real_escape_string功能。此外,mysql_* 在 php 中已弃用,您应该使用 mysqli 或 pdo 进行数据库工作。

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

于 2012-11-02T04:23:04.383 回答