将我的表单连接到 SQL
Connect my form to SQL
我试图将一个表单连接到我的,但似乎无法正常工作。有什么帮助吗?
这是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, 3, $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();
?>
我不断收到这条消息:
Connection failed: Can't connect to local MySQL server through socket
'/var/lib/mysql/mysql.sock' (111)
这个:
$conn = new mysqli($mysql, $podkupol_filmski, 3, $podkupol_konkurs);
应该是您的变量或字符串,您正在设置您不使用但在您的连接字符串中传递未设置变量的变量。
像这样尝试:
$conn = new mysqli($servername, $username, $password, $dbname);
旁注:
正如@developerwjk 在他的评论中提到的,'mysql' 应该更改为 localhost,或者实际的主机 ip 地址。
我试图将一个表单连接到我的,但似乎无法正常工作。有什么帮助吗?
这是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, 3, $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();
?>
我不断收到这条消息:
Connection failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)
这个:
$conn = new mysqli($mysql, $podkupol_filmski, 3, $podkupol_konkurs);
应该是您的变量或字符串,您正在设置您不使用但在您的连接字符串中传递未设置变量的变量。
像这样尝试:
$conn = new mysqli($servername, $username, $password, $dbname);
旁注:
正如@developerwjk 在他的评论中提到的,'mysql' 应该更改为 localhost,或者实际的主机 ip 地址。