我是否将HTML和PHP错误地连接到MySQL数据库?

时间:2018-12-15 10:42:22

标签: php html mysql

我到处都看过,发现了类似的问题,但找不到所需的答案。

我正在为装箱机的机器创建一个应用程序,它将从用户那里获得有关托盘的输入以及如何将其堆叠和定向的信息,并将输入到MySQL数据库中并将其存储以备将来使用。

我没有收到任何错误,也没有回声。但是,当我输入我的信息并按下“提交”按钮时,它只将我带到一个以纯文本形式打印PHP文件的页面。

这是我用来输入信息的表格。

<section class="bodyClass">
        <div class="body">
            <p class="par">INPUT INFORMATION TO INDUCT PALLET:</p>
            <div class="palletInfo">
            <form action="insert.php" method="post">
                <label for="palletId">Pallet ID:</label>
                <input type="text" name="palletId" id="palletId"></input></br>

                <label for="location">Location:</label>
                <input type="text" name="location" id="location"></input></br>

                <label for="pallet">Pallet type:</label>
                <input type="text" name="pallet" id="pallet"></input></br>

                <label for="stack">Stack type:</label>
                <input type="text" name="stack" id="stack"></input></br>

                <label for="distributor">Distributor:</label>
                <input type="text" name="distributor" id="distributor"></input></br>

                <label for="orientation">Orientation:</label>
                <input type="text" name="orientation" id="orientation"></input></br>

                <input type="submit" value="DECARTON" class="submit" ></button>
            </form>
            </div>
        </div>
    </section>

这是我访问数据库的PHP代码。

<?php

// Attempt connection
$link = mysqli_connect("localhost","root","decartondb");

// Check connection
if($link === false){
    die("ERROR: Could not connect." . mysqli_connect_error());
} else {
    echo "Connected Successfully.";
}

// Escape user inputs - for security.
$palletId = mysqli_real_escape_string($link, $_POST['palletId']);
$location = mysqli_real_escape_string($link, $_POST['location']);
$palletType = mysqli_real_escape_string($link, $_POST['palletType']);
$stackType = mysqli_real_escape_string($link, $_POST['stackType']);
$distributor  = mysqli_real_escape_string($link, $_POST['distributor']);
$orientation  = mysqli_real_escape_string($link, $_POST['orientation']);

// Attempt insert query execution
$sql = "INSERT INTO palletinfo (palletId, location, palletType, stackType, distributor, orientation)
VALUES ('$palletId', '$location', '$palletType','$stackType','$distributor','$orientation')";

if(mysqli_query($link, $sql)){
    echo "Records added successfully.";
} else{
    echo "Error: " . $sql . "<br>" . mysqli_error($link);
// close connection
mysqli_close($link);?>

请让我知道是否重复,并且已经回答了相同的问题,以便我可以找到它。谢谢。

0 个答案:

没有答案