简体   繁体   中英

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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