Drezek Posted July 19, 2009 Share Posted July 19, 2009 when using query string like http://127.0.0.1/profile.php?id=6436 how do i make it so if the id doesnt exist it displays a message saying the profile doesnt exist instead of displaying the page without any values thanks, Drezek Quote Link to comment https://forums.phpfreaks.com/topic/166491-quick-newb-php-question/ Share on other sites More sharing options...
Daniel0 Posted July 19, 2009 Share Posted July 19, 2009 if (!isset($_GET['id'])) { echo 'hi'; } Quote Link to comment https://forums.phpfreaks.com/topic/166491-quick-newb-php-question/#findComment-877948 Share on other sites More sharing options...
Drezek Posted July 19, 2009 Author Share Posted July 19, 2009 thank you that was very simple im learning php right now so im just messing around with it Quote Link to comment https://forums.phpfreaks.com/topic/166491-quick-newb-php-question/#findComment-877951 Share on other sites More sharing options...
Drezek Posted July 19, 2009 Author Share Posted July 19, 2009 what if i only have up to 7 ids and someone will try to load a page with the id of 8 Quote Link to comment https://forums.phpfreaks.com/topic/166491-quick-newb-php-question/#findComment-877953 Share on other sites More sharing options...
Daniel0 Posted July 19, 2009 Share Posted July 19, 2009 Well, that depends. If you're getting it from a database you could do something like this: $id = isset($_GET['id']) ? (int) $_GET['id'] : 0; // or you could do: $id = (int) filter_input(INPUT_GET, 'id', FILTER_UNSAFE_RAW) $result = mysql_query('SELECT * FROM users WHERE id = ' . $id . ' LIMIT 1'); if (mysql_num_rows($result)) { $user = mysql_fetch_assoc($result); // do stuff } else { echo 'User does not exist.'; } Quote Link to comment https://forums.phpfreaks.com/topic/166491-quick-newb-php-question/#findComment-877959 Share on other sites More sharing options...
Drezek Posted July 19, 2009 Author Share Posted July 19, 2009 not sure how that works but if i study it for a bit il bet il get it THANKS A BUNCH Quote Link to comment https://forums.phpfreaks.com/topic/166491-quick-newb-php-question/#findComment-877962 Share on other sites More sharing options...
Daniel0 Posted July 19, 2009 Share Posted July 19, 2009 Well, as always, there are many ways to do one thing, and which way you would want to use depends on the context. Quote Link to comment https://forums.phpfreaks.com/topic/166491-quick-newb-php-question/#findComment-877964 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.