“'字段列表中的未知列'尽管显然存在

时间:2017-10-23 11:12:35

标签: php html mysql database

所以我发现了很多关于我的问题的其他问题,但我无法将它们应用到我的问题中。

HTML表单:

<form action="Bestellingen.php" method="post">
Voornaam: <input type="text" name="voornaam"></br>
Achternaam: <input type="text" name="achternaam"></br>
Size: <select name="sizes">
        <option value="XS">Extra small</option>
        <option value="S">Small</option>
        <option value="M">Medium</option>
        <option value="L">Large</option>
        <option value="XL">Extra large</option>
        </select></br>
<font color = red>Truncate table: </font><input type="checkbox" name="truncate"></br>
<font color = red>Drop database: </font><input type="checkbox" name="drop"></br>
<input type="submit" name="submit">
</form>

查询:

$sql1 = "CREATE TABLE Bestellingen(
            Voornaam varchar (20),
            Achternaam varchar (20),
            Size SET('XS','S','M','L','XL')
            )";
            $sql2 = "INSERT INTO Bestellingen (Voornaam, Achternaam, Size) VALUES ('$_POST[voornaam]','$_POST[achternaam]','$_POST[sizes]')";

问题: (未知列&#39;尺寸&#39;在&#39;字段列表&#39;) 即使我给了查询 CREATE TABLE Bestellingen(尺寸SET(&#39; XS&#39;,&#39; S&#39;&#39; M&#39;,&#39; L&#39;,&#39; XL&#39; ;))

从其他答案我收集到的可能是我使用了错误的数据类型或将错误的数据类型传递给查询,但我无法找到解决方案。

非常感谢任何帮助

完整代码(虽然显然没有完成):

<html>
<head>
</head>
<body>

<form action="Bestellingen.php" method="post">
Voornaam: <input type="text" name="voornaam"></br>
Achternaam: <input type="text" name="achternaam"></br>
Size: <select name="sizes">
        <option value="XS">Extra small</option>
        <option value="S">Small</option>
        <option value="M">Medium</option>
        <option value="L">Large</option>
        <option value="XL">Extra large</option>
        </select></br>
<font color = red>Truncate table: </font><input type="checkbox" name="truncate"></br>
<font color = red>Drop database: </font><input type="checkbox" name="drop"></br>
<input type="submit" name="submit">
</form>

<?php

$con = mysqli_connect("localhost","Joeri","password");
mysqli_select_db($con,"databank");

function frontend($connection){
    $con = $connection;
    $entry = "SELECT * FROM Bestellingen";
    $entries = mysqli_query($con,$entry);
    echo "<table border=1>
    <tr>
    <th>Nr.</th>
    <th>Voornaam</th>
    <th>Achternaam</th>
    <th>Size</th>
    <th>Betaald</th>
    </tr>";
    $count = 1;
    while($record = mysqli_fetch_array($entries)){
        echo"<form action=Bestellingen.php method=post>";
        echo "<tr>";
        echo "<td>".$count."</td>";
        $count++;
        echo "<td>".$record['Voornaam']."</td>";
        echo "<td>".$record['Achternaam']."</td>";
        echo "<td>".$record['Size']."</td>";
        echo "<td>"./*$record['Betaald'].*/"</td>";
        echo "</tr>";
    }
echo "</table>";
}

if(isset($_POST['submit'])){

    if(!$con){
        die ("<font color=red>Can't connect: " . mysqli_connect_error() ."</font><br/>");
    }
    else{
        echo "<font color=green>Connection link succesful...</font></br>";
        if (mysqli_query($con,"CREATE DATABASE databank")){
            echo "<font color=green>Your database was created...</font></br>";
        }
        else{
            echo "<font color=green>Database found...   </font><font color=black>(" . mysqli_error($con) . ")</font></br>";
        }

        if(isset($_POST['drop'])){
                mysqli_query($con,"DROP DATABASE databank");
                echo "<font color=blue>Dropped database...</font></br>";
            }
            else{
            mysqli_select_db($con, "databank");
            $sql1 = "CREATE TABLE Bestellingen(
            Voornaam varchar (20),
            Achternaam varchar (20),
            Size SET('XS','S','M','L','XL'),
            Betaald set('ja','nee')
            )";
            $sql2 = "INSERT INTO Bestellingen (Voornaam, Achternaam, Size) VALUES ('$_POST[voornaam]','$_POST[achternaam]','$_POST[sizes]')";

            if (mysqli_query($con, $sql1)){
                echo "<font color=green>Table made succesfully...</font></br>";
            }
            else{
                echo "<font color=green>Table found... </font><font color=black> (" . mysqli_error($con) . ")</font></br>";
            }

            if(isset($_POST['truncate'])){
                mysqli_query($con,"TRUNCATE TABLE Bestellingen");
                echo "<font color=blue>Truncated table...</font></br>";
            }
            else{
                if (mysqli_query($con, $sql2)){
                    echo "<font color=green>Registered values to table succesfully...</font></br>";
                }
                else{
                    echo "<font color=red>Could not register values... </font><font color=black> (" . mysqli_error($con) . ")</font></br>";
                }
            }
            frontend($con);

            mysqli_close($con);
        }
    }
}
?>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

问题已结束; 我想我已经在之前的草稿中添加了前几列,并且已经在数据库中。 当我试图重新制作表格时,它已经存在并且没有添加&#34;尺寸&#34;柱。 固定: 我删除了我的表,因此可以再次创建它; 问题解决了

很抱歉给您带来不便。