Jump to content

Something must be so simple Sessions!!


deansaddigh

Recommended Posts

For some reason i cant echo out whats in the session.

 

Everything is fine , ive asked a coder and they cant figure it out either.

 

Page where session is started and saved

 

<?php session_start();?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php
include '../includes/connection.php';
?>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="../images/animated_favicon1.gif" />
<link rel="stylesheet" type="text/css" href="../css/layout.css" /> 



<title>Nextdayfrags.co.uk</title>
</head>

<body>
<!--wrapper to hold site-->
    <div id="wrapper">
    	
      <!--Logo holder-->
      <div id="header"></div>
        
        <div id="left">
       		<div class="nav">    
       			  	
	        	<ul>
					<li><a href="#">SPS frags</a></li>
					<li><a href="#">LPS frags</a></li>
					<li><a href="#">Soft Coral frags</a></li>
					<li><a href="#">Coral Frag packs</a></li>
					<li><a href="#">SPS Coral Colonies</a></li>
					<li><a href="#">LPS Coral Colonies</a></li>
	        		<li><a href="#">Anemones</a></li>
	        		<li><a href="#">Clean Up Critters/ Inverts</a></li>
	        		<li><a href="#">Coral Food</a></li>
	        		<li><a href="#">Reef Accesories</a></li>
	        		<li><a href="#">Gift Vouchers</a></li>
	        	
				</ul>
        	<div align="center">
        	 
			 <img src="images/paypal.png"/> 	
        		 
        	</div>
        	</div>
        </div>
        
        	<div id="right">
        
        		<?php
        		//Store details in variables 
        		$username=$_POST['username'];
			$password=$_POST['password']; 


			//Provent sql injections
			$username = mysql_real_escape_string($username);
			$password = mysql_real_escape_string($password);

			//Sql
			$query="SELECT * FROM users WHERE UserName='$username' and Password='$password'";
			$result=mysql_query($query);

			// Mysql_num_row is counting table row
			$count=mysql_num_rows($result);
			// If result matched $myusername and $mypassword, table row must be 1 row


			if($count==1)
			{
				// Register $myusername, $mypassword and redirect to file "login_success.php"
				$_SESSION['username']= $username;
				header("location:add_product_form.php");
			}
			else 
			{
				echo "Wrong Username or Password";
			}
			?>





        	
		</div>
          		



          
          
            
           
            
      
        
      
</div>
    
    
   

</body>
</html>

 

Page where i am echo out session variable

 

<? session_start();
if (isset($_SESSION['username']) == false) 
{
header("Location:login.php");
exit();
}	

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php
include '../includes/connection.php';
?>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="../images/animated_favicon1.gif" />
<link rel="stylesheet" type="text/css" href="../css/layout.css" /> 


<title>Nextdayfrags.co.uk</title>
</head>

<body>
<!--wrapper to hold site-->
    <div id="wrapper">
    	
      <!--Logo holder-->
      <div id="header"></div>
        
        <div id="left">       		 
       <div align="center">	
       	<img src="../images/paypal.png" alt="Paypal verified" /> 
       </div>
        </div>
        
        <div id="right">
   			
   			<?php 
   				
   				echo 'welcome';
   				echo $_SESSION['username'];
   				
   				
   				
   			$message = $_GET["message"];
   			
   			
   				if ( $message != "" )
   				{
   				echo $message;
   				}
   			
   			?>
   			
   			
		<form id="form" name="form" method="post" enctype="multipart/form-data" action="../admin/process_product.php">
		<fieldset>
		<legend>Use this form to add a product</legend>
		<h1>Add Product</h1>
		<p>Please use this form to add a product</p>

		<label>Product Name</label>
		<input type="text" name="name"/><br /><br />


		<label>Product Catagory</label>
		<select name ='category'>
		  <option>LPS frags</option>
		  <option>SPS frags</option>
		  <option>Soft Coral frags</option>
		  <option>Coral Frag packs</option>
		  <option>SPS Coral Colonies</option>
		  <option>LPS Coral Colonies</option>
		  <option>Anemones</option>
		</select><br /><br />

		<label>Product Quantity</label>
		<input type="text" name="quantity"/><br /><br />

		<label>Product Price</label>
		<input type="text" name="price"/><br /><br />

		<label>Product Description</label>
		<textarea cols="30" rows="4" name="description"></textarea><br /><br />

		 <input type="hidden" name="MAX_FILE_SIZE" value="500000000" />
             <label>Add Picture:</label>  <input name="uploadedfile" type="file"  /><br /><br />
            	
             <label>Video Embed code</label>
		<textarea cols="30" rows="4"  name="video"></textarea><br /><br />
            			
		<button type="submit" class="submit">Add Product</button>

		</fieldset>
		</form>

	</div>
   			
        	
       
          		
     </div>        
      

    
    
   

</body>
</html>

 

The error i get is

Notice: Undefined variable: _SESSION in C:\wamp\www\Php Shoping cart\admin\add_product_form.php on line 47

Link to comment
https://forums.phpfreaks.com/topic/182544-something-must-be-so-simple-sessions/
Share on other sites

Everything is fine , ive asked a coder and they cant figure it out either.

 

if everything were "fine", you wouldn't have a problem now, would you.

 

seems the session isn't being started.

 

try chainging your short tag to a full tag:

 

<?php
session_start();
//...rest of code...
?>

 

instead of:

 

<? session_start();

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.