将我的表单连接到SQL

时间:2015-01-21 20:01:00

标签: php mysql forms

我试图将表单连接到我,但似乎无法使其正常工作。有什么帮助吗?

这是HTML

<form action="info.php" method="post">
         <label for"email">Vaša e-mail adresa</label>
         <input type="email" name="EMAIL" required>
         <textarea name="recenzija" class="recenzija" rows="10" columns:"1" name="TEKST" required>Otkucajte ili kopirajte vaš tekst ovde (do oko 400 reči).</textarea>
                <input type="submit" class="submit" name="submit" value="Pošalji">
        </form

和PHP

<?php
$servername = "mysql";
$username = "podkupol_filmski";
$password = "123";
$dbname = "podkupol_konkurs";

// Create connection
$conn = new mysqli($mysql, $podkupol_filmski, $123, $podkupol_konkurs);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "INSERT INTO konkurs (EMAIL, TEKST)
VALUES ('EMAIL', 'TEKST')";

if ($conn->query($sql) === TRUE) {
    echo "Hvala!";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>

我一直收到这条消息:

  

连接失败:无法通过套接字连接到本地MySQL服务器   &#39; /var/lib/mysql/mysql.sock' (111)

1 个答案:

答案 0 :(得分:1)

此:

$conn = new mysqli($mysql, $podkupol_filmski, $123, $podkupol_konkurs);

应该是您的变量或字符串,您要设置不使用的变量,而是在连接字符串中传递未设置的变量。

尝试这样:

$conn = new mysqli($servername, $username, $password, $dbname);

旁注:

正如@developerwjk在评论中提到的,'mysql'应该更改为localhost,或实际的主机IP地址。