error on Session_Start()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • microguy
    New Member
    • Jan 2009
    • 4

    error on Session_Start()

    I am kind of new on PHP. I could not figure out what went wrong on my ph.

    Here is code:
    Code:
    <?php 
    
    include 'dbc.php';
    
    $user_email = mysql_real_escape_string($_POST['email']);
    
    if ($_POST['Submit']=='Login')
    {
    $pass = $_POST['pwd'];
    $sql = "SELECT id,user_email FROM rmusers WHERE 
                user_email = '$user_email' AND 
                user_pwd = '$pass' AND user_activated='1'"; 
    			
    $result = mysql_query($sql) or die (mysql_error()); 
    $num = mysql_num_rows($result);
    
    if ( $num != 0 ) { 
    
            // A matching row was found - the user is authenticated. 
    
           session_start(); 
    	   
    	   list($user_id, $user_email) = mysql_fetch_row($result);
    		// this sets variables in the session 
    		$_SESSION['user']= $user_email;  
    		
    			
    		if (isset($_GET['ret']) && !empty($_GET['ret']))
    		{
    		header("Location: $_GET[ret]");
    		} else
    		{
    		header("Location: myaccount.php");
    		}
    		//echo "Logged in...";
    		exit();
    
            header("Location: myaccount.php"); 
            } 
    
    
    header("Location: login.php?msg=Invalid Login");
    echo "Error:";
    exit();		
    }
    
    ?>
    
    <link href="styles.css" rel="stylesheet" type="text/css">
    
    <?php if (isset($_GET['msg'])) { echo "<div class=\"msg\"> $_GET[msg] </div>"; } ?>
    
    
    <p>&nbsp;</p><table width="40%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr> 
        <td bgcolor="#d5e8f9" class="mnuheader" >
    <div align="center"><font size="5"><strong>Login 
            Members</strong></font></div></td>
      </tr>
      <tr> 
        <td bgcolor="#e5ecf9" class="mnubody"><form name="form1" method="post" action="">
            <p>&nbsp;</p>
            <p align="center">Your Email 
              <input name="email" type="text" id="email">
            </p>
            <p align="center"> Password: 
              <input name="pwd" type="password" id="pwd">
            </p>
            <p align="center"> 
              <input type="submit" name="Submit" value="Login">
            </p>
            <p align="center"><a href="register.php">Register</a> | <a href="forgot.php">Forgot</a></p>
          </form></td>
      </tr>
    </table>

    Hope you can tell me what did I do wrong.
    Last edited by Markus; Jan 7 '09, 08:20 PM. Reason: added [code] tags
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Can you please let us know what error you receive?

    Comment

    • microguy
      New Member
      • Jan 2009
      • 4

      #3
      sorry

      Here are errors



      Warning: session_start() [function.sessio n-start]: Cannot send session cookie - headers already sent by (output started at /home/mysimon/public_html/deaflds/test2/dbc.php:20) in /home/mysimon/public_html/deaflds/test2/login.php on line 21

      Warning: session_start() [function.sessio n-start]: Cannot send session cache limiter - headers already sent (output started at /home/mysimon/public_html/deaflds/test2/dbc.php:20) in /home/mysimon/public_html/deaflds/test2/login.php on line 21

      Warning: Cannot modify header information - headers already sent by (output started at /home/mysimon/public_html/deaflds/test2/dbc.php:20) in /home/mysimon/public_html/deaflds/test2/login.php on line 33

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        have a look at dbc.php line 20, there must be some kind of output which causes the errors.

        Comment

        • microguy
          New Member
          • Jan 2009
          • 4

          #5
          there is nothing on line 20

          here is my code
          Code:
          <?php
          
          //Database Information
          	$dbhost = "localhost";
          	$dbname = "xxxxxxx";
          	$dbuser = "xxxxxxxxx";
          	$dbpass = "xxxxxxxx";
          
          
          
          
          
          
          // $link = mysql_connect("localhost","root","") or die("Couldn't make connection.");
          $link = mysql_connect ($dbhost, $dbuser, $dbpass)or die("Could not connection. ");
          
          $db = mysql_select_db($dbname, $link) or die("Couldn't select database");
          ?>
          Last edited by Markus; Jan 7 '09, 09:46 PM. Reason: added [code] tags. Microguy, please read your PMs.

          Comment

          • microguy
            New Member
            • Jan 2009
            • 4

            #6
            I got it working now. There were space on line 20. Right now I have login page with two button for register and forgot. When we click on register or forgot it goes to another page. I did not want that. When click on forgot and I want email address box with subit box show up on same page. How do we do that? Like hide the address box and submit button till click on forgot then it will show up. Something like that. Can someone tell me the codes?

            Comment

            • Atli
              Recognized Expert Expert
              • Nov 2006
              • 5062

              #7
              Glad you got it working.
              Originally posted by microguy
              When click on forgot and I want email address box with subit box show up on same page.
              That would be a job for JavaScript.
              Try posting this question in a new thread in the JavaScript forum.

              Comment

              Working...