DeanWhitehouse Posted May 4, 2008 Share Posted May 4, 2008 i have this code for a members page, and when someone enters an invalid URL with an id that doesn't exist it should echo a message, but it doesn't work, it just says email: hidden. any ideas <?php if ($_SESSION['is_valid'] == true){ if (isset($_GET['id'])) { if ((int) $_GET['id'] > 0) { $userid = $_GET['id']; $sql = "SELECT * FROM $user WHERE `user_id`='{$userid}' LIMIT 0,1;"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $userprofname = $row['user_name']; $profemail = $row['user_email']; echo "$userprofname<br>"; $show_email = $row['show_email']; if ($show_email == 1) { echo 'Email:<a href="mailto:'.$profemail.'"> Email Me</a>'; } elseif ($show_email == 0) { echo "Email: Hidden"; } exit(); } else { echo "Invalid user! <br />"; echo "<a href=\"members.php\">Return to Members</a>"; exit(); } } //No ID passed to page, display user list: $query = "SELECT user_id, user_name FROM $user"; $result = mysql_query($query) or die("Error:" . mysql_error()); if (mysql_num_rows($result) > 0) { echo "User List:<br />"; while ($row = mysql_fetch_assoc($result)) { echo '<a href="?id=' . $row['user_id'] . '">' . $row['user_name'] . '</a><br />'; } } } else { echo "Please login to view this page."; } ?> Quote Link to comment Share on other sites More sharing options...
Bauer418 Posted May 4, 2008 Share Posted May 4, 2008 After this line: $result = mysql_query($sql); Add this code: if (mysql_num_rows($result) < 1) { echo 'This ID does not exist in the database'; } Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted May 4, 2008 Author Share Posted May 4, 2008 ok, i tried this , but it still does the same <?php require_once 'includes/header.php'; require_once 'includes/db_connect.php'; ?><div class="bg"></div> <div class="clock"><?php echo gmdate('l, jS F Y');?> <span id="txt"></span></div> <div class="member"> <?php if ($_SESSION['is_valid'] == true){ if (isset($_GET['id'])) { if ((int) $_GET['id'] > 0) { $userid = $_GET['id']; $sql = "SELECT * FROM $user WHERE `user_id`='{$userid}' LIMIT 0,1;"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $userprofname = $row['user_name']; $profemail = $row['user_email']; echo "$userprofname<br>"; $show_email = $row['show_email']; if ($show_email == 1) { echo 'Email:<a href="mailto:'.$profemail.'"> Email Me</a>'; } elseif ($show_email == 0) { echo "Email: Hidden"; } exit(); } } //No ID passed to page, display user list: $query = "SELECT user_id, user_name FROM $user"; $result = mysql_query($query) or die("Error:" . mysql_error()); if (mysql_num_rows($result) < 1) { echo 'This ID does not exist in the database'; echo "<a href=\"members.php\">Return to Members</a>"; }if (mysql_num_rows($result) > 0) { echo "User List:<br />"; while ($row = mysql_fetch_assoc($result)) { echo '<a href="?id=' . $row['user_id'] . '">' . $row['user_name'] . '</a><br />'; } } } else { echo "Please login to view this page."; } ?> </div> <?php mysql_close(); require_once 'nav_bar.php'; require_once 'includes/footer.php'; ?> Quote Link to comment Share on other sites More sharing options...
ady01 Posted May 4, 2008 Share Posted May 4, 2008 Try this again after the $result = mysql_query($sql); if (!empty($_POST['email'])) { $e = escape_data($_POST['email']); } else { echo '<p><font color="red" size="+1">The email address you have entered is incorrect!</font></p'; $e = FALSE; Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted May 4, 2008 Author Share Posted May 4, 2008 ok, so it is now working with this code, <?php require_once 'includes/header.php'; require_once 'includes/db_connect.php'; ?><div class="bg"></div> <div class="clock"><?php echo gmdate('l, jS F Y');?> <span id="txt"></span></div> <div class="member"> <?php if ($_SESSION['is_valid'] == true){ if (isset($_GET['id'])) { if ((int) $_GET['id'] > 0) { $userid = $_GET['id']; $sql = "SELECT * FROM $user WHERE `user_id`='{$userid}' LIMIT 0,1;"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $userprofname = $row['user_name']; $profemail = $row['user_email']; echo "$userprofname<br>"; $show_email = $row['show_email']; if (mysql_num_rows($result) < 1) { echo 'This ID does not exist in the database'; } if ($show_email == 1) { echo 'Email:<a href="mailto:'.$profemail.'"> Email Me</a>'; } elseif ($show_email == 0) { echo "Email: Hidden"; } exit(); } else { echo "Unknown User ID! <br />"; echo "<a href=\"members.php\">Return to Members Page</a>"; exit(); } } //No ID passed to page, display user list: $query = "SELECT user_id, user_name FROM $user"; $result = mysql_query($query) or die("Error:" . mysql_error()); if (mysql_num_rows($result) > 0) { echo "User List:<br />"; while ($row = mysql_fetch_assoc($result)) { echo '<a href="?id=' . $row['user_id'] . '">' . $row['user_name'] . '</a><br />'; } } } else { echo "Please login to view this page."; } ?> </div> <?php mysql_close(); require_once 'nav_bar.php'; require_once 'includes/footer.php'; ?> but it is still showing the Email: Hidden Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted May 4, 2008 Author Share Posted May 4, 2008 solved, i just put exit(); after Quote Link to comment 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.