PHP形式的每个下拉值仅允许1个POST

时间:2018-10-09 09:12:39

标签: php html database post mysqli

我有一个简单的PHP表单,用于以价格插入“模型”(在dorpdown中)。 我想做的是您只能发布一次模型1,一次发布模型2,等等。 因此,如果您在下拉菜单中选择模型1并进行发布,然后再试一次,因为您已经发布了模型1,则不允许您这样做。

对不起我的英语不好

        <select name="model">
        <?  
        $modellen[1]= "Model 1";
        $modellen[2]= "Model 2";
        $modellen[3]= "Model 3";

        foreach ($modellen as $key => $value) 
        {
            echo "<option value='".$key."''>".$value."</option>";
        }
        ?>
        </select>


if(isset($_POST['toevoegen'])) 
    {
        $prijs = Safesql($_POST['prijs']);
        $moment = date("Y-m-d h:i:sa");
        $kiesmodel = Safesql($_POST['model']);
        if(!$mysqli->query("INSERT INTO prijzen (prijs, created, model) VALUES (".$prijs.",'".$moment."' , '".$kiesmodel."')")) {echo $mysqli->error;}
        else{ echo "het toevoegen is gelukt";} 
        Laden(0);
    }



 //show records from database
if ($query = $mysqli->query("SELECT * FROM prijzen")) { echo $mysqli->error;}

if ($query->num_rows >= 1) 
    {
    while($row = $query->fetch_assoc()) 
        {
            ?><tr><td><form action="index.php" method="post">
            <? echo "Model" . " " . $row['model']; ?><a href="index.php?verwijderen=<?php echo $row['id']; ?>"><img src="delete.png"></a>
            <a href="index.php?edit=<?php echo $row['id']; ?>"><img src="edit.png"></a><?
            echo "  prijs:" . $row['prijs']. "<br>" ."";?><?
        }
    }

1 个答案:

答案 0 :(得分:0)

尝试在插入之前添加验证

enable_if

也许可以帮助您