我正在尝试验证一个名称,确保该名称不被使用,但由于某种原因,验证错误一直在重复它,我希望它在用户使用之前显示“名称已经在使用“但我得到的这个名字已经在usename中已经在usename中已经在usename中已经在usename中已经在usename中已经在使用中”。我怎么能阻止它?
$types = array();
$result = mysql_query("SELECT * FROM `im_album` WHERE username = '".$user_data['username']."' ");
while(($row = mysql_fetch_assoc($result))) {
$types[] = $row['name'];
}
if (isset($_POST['img_album'])) {
$al_name = $_POST['name'];
$al_description = $_POST['description'];
$mode = $_POST['mode'];
if(empty($al_name)){
$errors[] = 'album name required';
}
if (strlen($al_name) > 55 || strlen($al_name) > 255) {
$errors[] = 'name fields are to long ';
}
foreach($types as $album){
if ($al_name == $album)
$errors[] = "name already in use";
}};
echo output_errors($errors);
答案 0 :(得分:3)
foreach($types as $album){
if ($al_name == $album) {
$errors[] = "name already in use";
break;
}
}
尝试这段代码,而不是那里的代码。