PHP: If one clear member, redirect to user profile
Yes so i want to, in the search results, if there´s one that matches completly of what you have entered, then it should go to profil.php?id=$row[id]
I tried by doing t开发者_StackOverflow中文版his:
$full_name = mysql_real_escape_string($_POST["search"]);
$Matchy = $get["firstname"] . " " . $get["lastname"];
if($full_name == $Matchy){
echo "redirect me";
}
Is this ok? It seems to work, but maybe there's a better solution for doing this?
And how do I redirect without using header, as it already begun at the top..?
Sure it'll work, just remember a few things.
This will make usernames (names) case sensitive, and someone will have to only enter 1 space, they'll have to remember to do firstname lastname, not lastname firstname like some might assume. Depending on how you are retrieving $get it could be faster and more efficient to do a direct DB look up.
Edit: to make them not sensitive, you can lowercase them, either store them lowered cased or just lower case for comparason. i.e
$full_name = strtolower(mysql_real_escape_string($_POST["search"]));
$Matchy = strtolower($get["firstname"]) . " " . strtolower($get["lastname"]);
$full_name = mysql_real_escape_string($_POST["search"]);
$Matchy = $get["firstname"] . " " . $get["lastname"];
if($full_name == $Matchy){
echo "redirect me";
}
This is an another way to do it: (and taking Viper's comment in consideration)
- concatenate strings
- make them common case (lower / upper)
- remove spaces in them. <= This is important, where end user may include extra spaces during start / end of between names.. EG: instead of
"Tom Cruise"
I may write in " Tom Cruise " , trim will remove spaces from both ends, so , you can use that individually in the get[fname] and get[lname]
.
$Matchy = trim(strtolower($get["firstname"])) . " " . trim(strtolower($get["lastname"]));
if(strtolower($full_name) == $Matchy){
echo "redirect me";
}
精彩评论