Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

check if name exists

$
0
0

hi just wondering how i would go about checking if a companys name is already in use and if it is show a message at the side saying u cant use this name as its already in use, i know how i would do the error message but i got no clue on how to do the check im guessing you use a sql query but i dont really know.

this is the format ive been doing my code in.

 if (empty($_POST["companyname"]))
{
    $errors['companyname'] = "Please Enter Your companyname";
}elseif(preg_match_all("/[(?\/<>*:.@)]/i",$_POST['companyname'],$matches)){ // list of invalid characters

    #echo '<pre>',print_r($matches),'</pre>';
    $invalid_characters = implode(",",$matches[0]);
    $errors['companyname'] = 'Cannot use '.$invalid_characters;

} 
elseif(strlen($_POST['companyname']) > 220)
{
    $errors['companyname'] = 'Company name must be less then 220 characters';
}
elseif(strpos($_POST['companyname'], 'The') !== false)
{
    $errors['companyname'] = 'Company Names cant start with The';
}
elseif(strpos($_POST['companyname'], 'the') !== false)
{
    $errors['companyname'] = 'Company Names cant start with the';
}
elseif(strpos($_POST['companyname'], 'THE') !== false)
{
    $errors['companyname'] = 'Company Names cant start with THE';
}

else
{
    $companyname = test_input($_POST["companyname"]);
}

Viewing all articles
Browse latest Browse all 13200

Trending Articles