problem with SESSION help me plzzzz

Discussion in 'PHP' started by logieen, May 25, 2007.

  1. #1
    Hi every one I used SESSION in my code to let the user update his file it is a simple code it work but it show me a warning I don't know why so please help me to solve this problem

    form code
    <?php
    session_start();
    
    if(!isset($_SESSION['loggedin'])) {	
      print'<p align="right"><font size=4 face=AGA Dimnah Regular color=#DAB936> <b> your not register </font></b>
    <br /> <a href="register.php"> register </a></p>';
       exit();					}
    ?>
    
    <html>
    <style type="text/css">
    	body {
    <?php
    
    // Address error handing.
    ini_set ('display_errors', 1);
    error_reporting (E_ALL & ~E_NOTICE);
    
    // Check for a bg_color value.
    if (isset ($_COOKIE['bg_color'])) {
    	print "\t\tbackground-color: {$_COOKIE['bg_color']};\n";
    } else {
    	print "\t\tbackground-color: #ffffff;\n";
    }
    
    
    
    ?>
    	}
     </style>
    
    <head>
    <title>update page</title>
    <!--favorite-->
    <SCRIPT language="JavaScript1.2">
    var bookmarkurl="http://localhost/finalproject/index.php";
    var bookmarktitle="cook site";
    function addbookmark(){
    if (document.all)
    window.external.AddFavorite(bookmarkurl,bookmarktitle);
    }
    </SCRIPT>
    <!--end-favorite-->
    </head>
    
    <body>
    
    <table border="0" width="100%" id="table1" height="578" cellspacing="0" cellpadding="0">
    	<tr>
    		<td height="1" colspan="2">
    		<p>
    		</td>
    	</tr>
    	<tr>
    		<td height="1" colspan="2">
    		<p dir="rtl" align="center">
    	</td>
    	</tr>
    	<tr>
      		<td height="127" width="83%">
    		<p dir="rtl">
      </td>
      		<td height="127" width="17%" background="image/43.gif">
      <?php
    		if(isset($_SESSION['loggedin'])){
        print '
    		<p align="center"><font size=3 face=AGA Dimnah Regular color=#826C51> <b>  Hi <br/> ** ' .$_SESSION['loggedin'] . ' **  </font></b>
    <br /></p>'; }?>
    
    </td>
    	</tr>
    	<tr>
    		<td width="100%" background="image/35.gif" rowspan="2" colspan="2">
    		<div style="position: absolute; width: 552px; height: 483px; z-index: 1; left: 212px; top: 172px" id="layer1">
    
    <?php
    $dbc = @mysql_connect ('localhost','root','');
       $db_selected = mysql_select_db('recipes_club', $dbc);
    
    mysql_query("set charset cp1256");
    
    $result = mysql_query("SELECT * FROM user ", $dbc);
    
    $num_rows = mysql_num_rows($result);
    
    echo '<div align="center"><p>';
    $name=$_SESSION['loggedin'];
    
    $query = "SELECT * FROM user WHERE name ='$name'";
    if ($r = mysql_query ($query)) { // Run the query.
    $row = mysql_fetch_array ($r); // Retrieve the information.
    // Make the form.
    
    print"<form action='p1.php' method='post'>";
    print"<div align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\">";
    
    print"<font face=\"AGA Dimnah Regular\" color=#E3D1AC size=6 >to update your profile {$row['name']}</font><br /><br />";
    print'<br><font face="AGA Aladdin Regular" color="#C8A459" size=5><P><br /></font>';
    print'<font face="AL-Hor" size="5" color="#AC8959" align=rigth> password </font><input type="password" name="password" value="' . $row['password'] .'"/><br /><br />';
    
    
    print'<font face="AL-Hor" size="5" color="#AC8959" align=rigth> email </font><input type="text" name="email" value="' . $row['email'] . '" /><br />';
    
    print'<br /><font face="AL-Hor" size="5" color="#AC8959" align=rigth>  countery  </font>
    
    <select name=countery[] >
      <option value="' . $row['countery'] .'">' . $row['countery'] .'</option>
    <option value=countery>countery</option>
       </select>
       ';
    
    print'<br />
    <input type="submit" name="submit" value="!Update" /></form>';
    print'</div>';}
    else { // Couldn't get the information.
    print "<p>Could not retrieve the entry because: <b>" . mysql_error() . "</b>. The query was $query.</p>";
     }
      
      print '
    	</table>
    ';
    
    ?>
    </div>
    </td>
    </div>
    </td>
    		</tr>
    		
    </table>
    
    </body>
    
    </html>
    Code (markup):
    this is printscreen for it

    http://www.arbwb.com/img/download.php?file=7bbc06da4c0cad941c422ec76b9ea781


    action code
    
    <?php
    session_start();
    
    if(!isset($_SESSION['loggedin'])) {		  print'<p align="right"><font size=4 face=AGA Dimnah Regular color=#DAB936> <b> your not register</font></b>
    <br /> <a href="register.php"> register</a></p>';
       exit();					}
    ?>
    
    <html>
    <style type="text/css">
    	body {
    <?php
    
    // Address error handing.
    ini_set ('display_errors', 1);
    error_reporting (E_ALL & ~E_NOTICE);
    
    // Check for a bg_color value.
    if (isset ($_COOKIE['bg_color'])) {
    	print "\t\tbackground-color: {$_COOKIE['bg_color']};\n";
    } else {
    	print "\t\tbackground-color: #ffffff;\n";
    }
    
    
    
    ?>
    	}
     </style>
    
    <head>
    <title>update page</title>
    <!--favorite-->
    <SCRIPT language="JavaScript1.2">
    var bookmarkurl="http://localhost/finalproject/index.php";
    var bookmarktitle="cook site";
    function addbookmark(){
    if (document.all)
    window.external.AddFavorite(bookmarkurl,bookmarktitle);
    }
    </SCRIPT>
    <!--end-favorite-->
    </head>
    
    <body>
    
    <table border="0" width="97%" id="table1" height="693" cellspacing="0" cellpadding="0">
    	<tr>
    		<td height="19" colspan="2">
    		<p>
    		&nbsp;</td>
    	</tr>
    	<tr>
    		<td height="19" colspan="2">
    		<p dir="rtl" align="center">
    		&nbsp;</td>
    	</tr>
    	<tr>
    		<td height="133">
    		</td>
    		<td height="133" width="17%" background="image/43.gif">
    		<?php
    		if(isset($_SESSION['loggedin'])){
        print '
    		<p align="center"><font size=3 face=AGA Dimnah Regular color=#826C51> <b>  Hi <br/> ** ' .$_SESSION['loggedin'] . ' **  </font></b>
    <br /></p>'; }?>
    </td>
    			</tr>
    	<tr>
    		<td width="99%" background="image/32.gif" rowspan="2" colspan="2">
    		<div style="position: absolute; width: 552px; height: 303px; z-index: 1; left: 207px; top: 208px" id="layer1">
    
    
    <?php
       $dbc = @mysql_connect ('localhost','root','');
       $db_selected = mysql_select_db('recipes_club', $dbc);
    
    mysql_query("set charset cp1256");
       $name=$_SESSION['loggedin'];
      $password =$_POST['password'];
      $email=$_POST['email'];
      $countery=$_POST['countery'];
    
       ini_set ('display_errors', 1);
    error_reporting (E_ALL & ~E_NOTICE);
         
    
    
    $name=$_SESSION[loggedin];
    if (empty ($password)) {
    	echo '<script language="javascript">
     window.alert("please enter your password");
     </script>';
    
    
     }
    
     else if (empty ($countery)) {
     echo '<script language="javascript">
     window.alert("choose your country");
     </script>';
    
    } ELSE{ if (is_array ($_POST['countery'])) {
     foreach ($_POST['countery'] as $c)
    $query = "UPDATE user SET password='{$_POST['password']}',countery='$c',email='{$_POST['email']}' WHERE name='$name'";
    $r = mysql_query ($query); // Execute the query.
    // Report on the result.
    
    if (mysql_affected_rows() == 1) {
    
    
    print '<br /> <p><div align=center><font face="AGA Dimnah Regular" color="#E3D1AC" size=10><br /><br /><b />your profile has been update</font></div></p>';	}
    else {
    print "<p>Could not update the entry because: <b>" . mysql_error() . "</b>. The query was $query.</p>"; }}
    else { // Display the entry in a form.
    // Check for a valid entry ID in the URL.
       }
    }
    
    
       mysql_close();
    
    ?>
    
    </div>
    </td>
    </div>
    </td>
    		</tr>
    		
    </table>
    
    </body>
    
    </html>
    Code (markup):

    this is printscreen for it

    http://www.arbwb.com/img/download.php?file=71a59bf52929c5f1e1e3bde6979afe6b


    so help me plzzzzzzzzzzzzz :( :( :(
     
    logieen, May 25, 2007 IP
  2. projectshifter

    projectshifter Peon

    Messages:
    394
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    When you do session_start(), it needs to come before any output, so you can't have HTML or anything before <?php session_start(); There are way around it with output buffering, but make sure you have NOTHING (including white space and tabs) before you start your php block, and that session_start() comes before any output.
     
    projectshifter, May 25, 2007 IP