Jump to content

[SOLVED] session_start() Warning and wrong redirect in registration.php


TheFreak

Recommended Posts

Here is my code,first i am getting a warning

 

PHP Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent in C:\Documents and Settings\Freak\Desktop\Mainsite\registration.php on line 2 PHP 
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent in C:\Documents and Settings\Freak\Desktop\Mainsite\registration.php on line 2 

 

Second i am getting redirected to registration.php even though user is not present already in database.It should only redirect when user is already present.

 

My Code

 

<?php
session_start();
include 'connect.php';
include 'functions.php';
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="style.css" type="text/css" />

</head>
<body>
<span style="text-align: left;
    color: #941515;
    font-family:Verdana,Helvetica,Arial,sans-serif;
    font-size:13px;
    position: absolute;
    top:1%;
    left:250px;"><?php include 'memmenu.php'; ?></span>

<span style="text-align: left;
    color: #941515; 
    font-family:Verdana,Helvetica,Arial,sans-serif;
    font-size:13px;
    position: absolute;
    top:3%;
    left:710px;"><a href="">HOME</a> | <a href="">MEMBERSHIP PLANS</a> | <a href="">STORES</a> | <a href="">CARE</a></span> 

<table>
<tr>
<td>
<span style="position: relative; margin-left: 42px ; ">
<img src="images/logo.gif" width="189" height="74"/>
</span>
</td>
<td>
<div class="searchmain">
<div class="searchtext">
SEARCH
</div>
<select class="searchside"><option>All</option><option>Director</option><option>Genre</option><option>Producer</option></select> 
<div>
<form>
<input name="login" type="text" class="searchinner"  />
</form>
</div>
<div class="searchside"> 
</div>
</div> 
</td>
</tr>
</table>
<div align="center" class="regcont">
<div>
         <ul class="top blue">
    <li><a href="index.php" title="">MOVIES</a></li>
    <li><a href="common.php" title="">TELEVISION</a></li>
    <li><a href="documentary.php" title="" >DOCUMENTRIES</a></li>
    <li><a href="plays.php" title="">PLAYS</a></li>
    <li><a href="kids.php" title="">KIDS</a></li>
    <li><a href="videos.php" title="">VIDEOS</a></li>
    <li><a href="stores.php" title="">STORES</a></li>
        </ul>
        </div>
   <div class="regbox">
   <?php if(isset($_POST['submit']))
     {
       $username= clean($_POST['username']);
       $password= clean($_POST['password']);
       $email= clean($_POST['email']);
       $address= clean($_POST['address']);
       $fname= clean($_POST['fname']);
       $lname= clean($_POST['lname']);
       $pcode= clean($_POST['pcode']);
       $memplan= $_POST['memplan'];
       
       $password= md5($password);
       
        $check2 = 0;
       $check="SELECT * FROM users WHERE username = '$username'";
       $check1=mysql_query($check) or die("Could not get category address");
       $check2 = mysql_num_rows($check1);  
          if ($check2 != 0) 
         {
       print "<br>UserName Already present,please choose another."; 
       print "<META http-equiv='refresh' content='0;URL='registration.php'>" ;
        }
       else
         { 
       $sql ="INSERT INTO users (username, password, email, address, city, pcode, memplan) VALUES ('$username', '$password', '$email', '$address', '$city', '$pcode', '$memplan')";
       $sql1= mysql_query($sql) or die("Could not get user address");
       print " <br>User added,Thankyou";
       $_SESSION['username'] = $username;
      print "<meta http-equiv='refresh' content='0;url=index.php'>" ;
         }
        print "</td></tr></table>";
          
      }
   else
   {
   print "<br><br><h3>REGISTRATION</h3><br>";  ?>
        <form id="Form" name="Form" method="POST" action="">
        <table width="300" border="0" align="center" cellpadding="2" cellspacing="0">
        <tr>
        <td width="112"><b><br><h5>UserName</h5></b></td>
        <td width="188"><br><input name="username" type="text" class="textfield" id="username" /></td>
        </tr>
        <tr>
        <td width="112"><b><br><h5>Password</h5></b></td>
        <td width="188"><br><input name="password" type="text" class="textfield" id="password" /></td>
        </tr>
        <tr>
        <tr>
        <td width="112"><b><br><h5>Email</h5></b></td>
        <td width="188"><br><input name="email" type="text" class="textfield" id="email" /></td>
        </tr>
        <tr>
        <td width="112"><b><br><h5>Address</h5></b></td>
        <td width="188"><br><input name="address" type="text" class="textfield" id="address" /></td>
        </tr>
        <tr>
        <td width="112"><b><br><h5>City</h5></b></td>
        <td width="188"><br><input name="city" type="text" class="textfield" id="city" /></td>
        </tr>
        <tr>
        <td width="112"><b><br><h5>Pin Code</h5></b></td>
        <td width="188"><br><input name="pcode" type="text" class="textfield" id="pcode" /></td>
        </tr>
        <tr>
        <td width="112"><b><br><h5>Plan</h5></b></td>
        <td width="188"><br><select name="memplan" class="textfield"><option name="memplan" value="Platimun">Platinum</option><option name="memplan" value="Gold">Gold</option><option name="memplan" value="Silver">Silver</option></td>
        </tr>
        <td> </td>
       <td><br><input type="submit" name="submit" value="submit" /></td>
      </tr>
      </table>
      </form>
    <?php  }  ?>
   </div>     
</div>
<p>
    <a href="http://jigsaw.w3.org/css-validator/check/referer">
        <img style="border:0;width:88px;height:31px"
            src="http://jigsaw.w3.org/css-validator/images/vcss"
            alt="Valid CSS!" />
    </a>
</p>
      
</body>
</html>

I changed the code a bit and it worked,even though its the same :/

 

 if ($check2 != 0) 
         {
       print "<br>UserName Already present,please choose another."; ?>
       <META http-equiv="refresh" content="0;URL=registration.php"> <?php
        }
       else
         { 
       $sql ="INSERT INTO users (username, password, email, address, city, pcode, memplan) VALUES ('$username', '$password', '$email', '$address', '$city', '$pcode', '$memplan')";
       $sql1= mysql_query($sql) or die("Could not get user address");
       print " <br>User added,Thankyou";
       $_SESSION['username'] = $username;
      ?> <META http-equiv="refresh" content="0;URL=index.php"> <?php
         }

 

 

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.