普通网友 2015-01-21 20:00
浏览 36
已采纳

将我的表单连接到SQL

I was trying to connect a form to my but can't seem to make it work. Any help, please?

Here is the 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

And the 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();
?>

I keep getting this message:

Connection failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)

  • 写回答

1条回答 默认 最新

  • drdawt9210 2015-01-21 20:03
    关注

    This:

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

    should be either your variables or strings, you are setting variables which you don't use but pass unset variables in you connection string.

    try it like this:

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

    SIDENOTE:

    As @developerwjk has mentioned in his comment, 'mysql' should be changed to localhost, or the actual hosts ip address.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题