0
<?php
session_start();

$con = mysql_connect("localhost","root","");
$sql = mysql_select_db("blog", $con) or die(mysql_error());

?>

<html>
	<head>
		<title>///</title>
	</head>
		<body>
			<div id="admin-content">
			<?php
			
			if($_SESSION['uid']){
				$sel = "SELECT * FROM `users` WHERE `id`='".$_SESSION['uid']."' ";
				$result = mysql_query($sql) or die (mysql_error());
		
			if(mysql_num_rows($res) == 0){
				session_destroy();
			echo "Please <a href='login.php'>Login</a> to your account, or <a href='register.php'>Register</a> new account!";
				}else{
				$row = mysql_fetch_assoc($res);
				echo "Welcome back, <a href='index.php?act=profile&id=".$row['id']."'>".$row['username']."</a>! <a href='logout.php' onClick='return confirmLogout()'>logout</a>";
				if($row['admin'] == '1'){
								echo "admin Section";
							}
				
					}
					} else {
					echo "Please <a href='login.php'>Login</a> to your account, or <a href='register.php'>Register</a> new account!";
					}
					
			?>
		</div>
		</body>
</html>

I got error on line 17, which is "Undefined Index: uid". I'm a new in php please help me guys

2
Contributors
4
Replies
7
Views
6 Years
Discussion Span
Last Post by luweegee
0

Try replacing line 17 with the following if statement:

if(isset($_SESSION['uid']) && $_SESSION['uid']){
0

thanks sir it works...but why? can you explain sir?

Well basically when checking for the value of a variable (in this case checking in the if statement) you first must check if it's defined unless you know it's defined. So in this instance the variable $_SESSION was never given a value so it triggered an error. However when the if (isset($_SESSION) was put before it, php check if the variable had a value then php found out that no it didn't so false the if statment and didn't pass on any error messages.

0

thanks sir for helping me. I must defined 1st my variable before the declaration of $_SESSION...

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.