简体   繁体   English

如果值不存在则更新表

[英]Update Table if value not exists

I have two select box which values are我有两个选择框,它们的值是

<select>
<option value="">I</option>
<option value="">II</option>
<option value="">III</option>
</select>

<select>
<option value="">I</option>
<option value="">II</option>
<option value="">III</option>
<option value="">IV</option>
<option value="">V</option>

</select>

My Scenario is when i select a class from first select box then after i select class from second select box.It will update the student Class "If value not exist in table."我的场景是当我从第一个选择框中选择一个班级,然后在我从第二个选择框选择班级之后。它将更新学生班级“如果表中不存在值”。 otherwise i will show error like this "Class already exist".否则我会显示这样的错误“类已经存在”。 For Example If i want to update student from "I" to "II" then value of 2nd select box should not in table.. please somebody help me.例如,如果我想将学生从“I”更新为“II”,那么第二个选择框的值不应该在表中..请有人帮助我。

There is one problem your not setting value and its empty.有一个问题是你没有设置并且它是空的。 By which the values you select wont be added or updated to your database.您选择的值不会被添加或更新到您的数据库中。

The second is you have not given the name to your select dropdown by which even if you select the values it wont be posted to your action.第二个是你没有给你的选择下拉列表命名,即使你选择了它也不会发布到你的操作中的值。

<form action="update_student.php" method="post">
    <select name="from_class">
        <option value="I">I</option>
        <option value="II">II</option>
        <option value="III">III</option>
    </select>

    <select name="to_class">
        <option value="I">I</option>
        <option value="II">II</option>
        <option value="III">III</option>
        <option value="IV">IV</option>
        <option value="V">V</option>
    </select>

    <input type="submit" value="Upgrade">
</form>

Suggestion:建议:

And even you need to validate that the student must be promoted to the next class and not the class which he is already completed.甚至您还需要确认学生必须晋升到下一堂课,而不是他已经完成的班级。

Eg: If your upgrading the student from II to III which is totally fine but you must not allow II to I.例如:如果您将学生从 II 升级到 III,这完全没问题,但您不能让 II 升级到 I。

In case if the user has asked for this kind of workflow then atleast you must prompt with confirmation for degrading the class from II to I如果用户要求这种工作流程,那么至少您必须提示确认将类从 II 降级到 I

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM