I have a profile.php page, and when someone views their own profile, it grabs the id of their user and adds profile.php?UserID=* (* being the id number of a user). At the moment, there is no legit way to look at others profiles, but you are able to change the id in the url. Problem is, you can go to the profile of a user who doesn’t exist and make it will be the default profile page without anything on it. Is there a way to get the id from a page/url and see if it exists or not, and if not, to redirect to a certain page?
<?php
include('./dbnotseen/global.php');
$profile = mysql_query("SELECT * FROM admin WHERE username='$username'");
$row = mysql_fetch_array($profile);
$username = $row['username'];
if (($session_username)) {
}else {
("location: index.php");
}
//max per page
$per_page = 1;
//get start variable
$start = $_GET['UserID'];
//count records
$record_count = mysql_num_rows(mysql_query("SELECT * FROM admin"));
//count max pages
$mac_pages = $record_count / $per_page;
if (!$start)
$start = 0;
//display data
$get = mysql_query("SELECT * FROM admin WHERE id='$start'");
while ($row = mysql_fetch_array($get)) {
$id = $row['username'];
$picture = $row['picture'];
$admin = $row['admin'];
$status = $row['status'];
$desc = $row['description'];
$twitter = $row['twitter'];
}
?>
That’s the main part of the PHP in the profile.php. The rest is just getting a status, description etc.
You can check if the result set of your mysql query is not empty. Doing it with
mysql_functions would look like so:This would give you an idea on how you should approach it, but as
@Madara Uchihasuggested in the comment to your question, you should stop usingmysql_functions.