gpt4 book ai didi

php - 如何限制MySQL插入中的值?

转载 作者:行者123 更新时间:2023-11-29 08:17:25 25 4
gpt4 key购买 nike

所以我在学校有一个简单的数据库练习,我快完成了,但我不知道如何限制值。

我有一个数据库,例如:

ID | Name | Age 1 | John | 20 2 | Jack | 30

等等。

有没有办法阻止用户输入低于 18 岁的年龄?我已经搜索了很多,但没有找到答案...提前致谢!

最佳答案

使用 PHP,您可以使用以下内容验证表单:

$enteredAge = 17; //from the user

$minAge = 18;
$maxAge = 125; //debatable

if( !in_array( $enteredAge, range( $minAge, $maxAge) ) ){
//Incorrect age.
}

如果您觉得数组对于此类事物来说太“昂贵”:

$enteredAge = 17; //from the user

$minAge = 18;
$maxAge = 125; //debatable

if($enteredAge < $minAge || $enteredAge > $maxAge){
//Incorrect age.
}

关于php - 如何限制MySQL插入中的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20302026/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com