OilSheikh Posted May 1, 2007 Share Posted May 1, 2007 Hi, I copied this code from a Site's Shopping Cart Tutorial and it doens't work! Yes, I copied it carefully and followed all the advice! But, I just get this error - [color=navy] Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Program Files\ZSOFT\XAMPP\xampp\htdocs\menu.php: in C:\Program Files\ZSOFT\XAMPP\xampp\htdocs\SQL2.php on line 13 Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\ZSOFT\XAMPP\xampp\htdocs\menu.php: in C:\Program Files\ZSOFT\XAMPP\xampp\htdocs\SQL2.php on line 14 [/color] Menu.php is a CSS based menu. No PHP or SQL in it. I fear that the session started in SQL2.php is conflicting with the session already started during LOGIN LOGIN.PHP <?php ob_start(); include("menu.php"); include("SQL.php"); ######### CHECKS THAT FIELDS ARE NOT EMPTY ########## if (isset($_POST ['submit'])) { $usern = $_POST['username']; $passw = $_POST['pass']; $encryptedpass = md5($_POST['pass']); if (!$usern | !$passw) { die ('<br><br><br><font face="Verdana" size="4" color = red>ERROR: Please make sure that all Information is provided.</font> <br><br> <input type="button" value=" Retry " onClick="history.go(-1)"> '); } ######### CHECKS IF username AND CORRESPONDING password EVEN EXIST ! ########## $check = mysql_query("SELECT * FROM customer WHERE username = '$usern' AND password = '$encryptedpass' ") or die(mysql_error()); $check2 = mysql_num_rows($check); if ($check2 == 1) { session_register("usern"); session_register("passw"); header("location:acc.php"); } else if ($check2 == 0) { die ('<br><br><br><font face="Verdana" size="4" color = red>ERROR : The Username and/or Password you have entered does not exist. <br><br>If you are a New User, please <a href = "register.php"><u>Register</u></a> first. </font> <br><br> <input type="button" value=" Retry " onClick="history.go(-1)">'); } } else { ob_end_flush(); ?> <html> <head> <title>Login to your Account or Register for a new Account</title> <link rel="stylesheet" href="styler.css"> </head> <body> <br><br><br> <h2>Please Log in to view Your Account<br><br></h2> <h3> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border="0" width="101%" cellspacing="1" id="table1" bordercolorlight="#0066FF" height="75"> <tr> <td width="106" height="48">Username</td> <td height="48" width="259"> <input type = "text" name = "username" size="34" maxlength ="7" style = "color:blue"></td> <td height="48" width="32"> </td> <td height="95" rowspan="2">Are you a New User ? Please Register.</td> </tr> <tr> <td width="106" height="47">Password</td> <td height="47" width="259"> <input type = "password" name = "pass" size="34" maxlength = "7" style = "color:blue"></td> <td height="47" width="32"> </td> </tr> <tr> <td width="106"> </td> <td width="259"> </td> <td width="32"> </td> <td> </td> </tr> <tr> <td width="106"> </td> <td width="259"> <p align="center"> <input type = "submit" name = "submit" value = "" style="background : url(login.jpg); width:107px; height:25px; "> </td> <td width="32"> </td> <td> <a href="register.php"> <img border="0" src="reg.jpg" width="101" height="20"></a></td> </tr> <tr> <td width="106"> </td> <td width="259"> </td> <td width="32"> </td> <td> </td> </tr> <tr> <td width="365" colspan="2"><font size="2">Forgotten your Password? <span style="background-color: #FFFFFF"> <a href="recover.php">Recover your password</a>.</span></font></td> <td width="32"> </td> <td> </td> </tr> </table> </form> </h3> <?php include("base.php"); ?> </body> </html> <?php } ?> Here's the SQL2.php code <?php mysql_connect ("localhost", "root" , "zforce") or die (mysql_error()); mysql_select_db("express") or die (mysql_error()); function GetCartId() { if (isset($_COOKIE["cartid"]) ) { return $_COOKIE["cartid"]; } else { session_start(); setcookie("cartid",session_id(),time()+((3600*24)*2) ); return session_id(); } } ?> Here's the code for the Shopping Cart , CART.PHP <?php include("menu.php"); include("SQL2.php"); ?> <script language="JavaScript"> function UpdateQty(item) { productid = product.name; newQty = product.options[product.selectedIndex].text; document.location.href = 'cart.php?action=update_item&id='+productid+'&qty='+newQty; } </script> <?php switch($_GET["action"]) { case "add_item": { AddItem($_GET["id"], $_GET["qty"]); ShowCart(); break; } case "update_item": { UpdateItem($_GET["id"], $_GET["qty"]); ShowCart(); break; } case "remove_item": { RemoveItem($_GET["id"]); ShowCart(); break; } default: { ShowCart(); } } function AddItem($itemid, $qty) { $result = mysql_query("select count(*) from cart where cookieid = '" . GetCartId() . "' and productid = $productid"); $row = mysql_fetch_row($result); $numRows = $row[0]; if($numRows == 0) { // This item doesn't exist in the users cart, // we will add it with an insert query mysql_query("INSERT INTO cart(cookieid, productid, qty) values('" . GetCartId() . "', $productid, $qty)"); } else { // This item already exists in the users cart, // we will update it instead UpdateItem($productid, $qty); } } function UpdateItem($productid, $qty) { mysql_query("UPDATE cart set qty = $qty where cookieid = '" . GetCartId() . "' and productid = $productid"); } function RemoveItem($productid) { mysql_query("DELETE from cart where cookieId = '" . GetCartId() . "' and productid = $productid"); } function ShowCart() { $result = mysql_query("select * from cart inner join product on cart.productid = product.productid where cart.cookieId = '" . GetCartId() . "' order by product.name asc"); while($row = mysql_fetch_array($result)) { // Increment the total cost of all items $totalCost += ($row["qty"] * $row["price"]); ?> <html> <head></head> <body> <table> <tr> <td width="15%" height="25"> <font face="verdana" size="1" color="black"> <select name="<?php echo $row["productid"]; ?>" onChange="UpdateQty(this)"> <?php for($i = 1; $i <= 5; $i++) { echo "<option "; if($row["qty"] == $i) { echo " SELECTED "; } echo ">" . $i . "</option>"; } ?> </select> </font> </td> <td width="55%" height="25"> <font face="verdana" size="1" color="black"> <?php echo $row["name"]; ?> </font> </td> <td width="20%" height="25"> <font face="verdana" size="1" color="black"> $<?php echo number_format($row["price"], 2, ".", ","); ?> </font> </td> <td width="10%" height="25"> <font face="verdana" size="1" color="black"> <a href="cart.php?action=remove_item&id=<?php echo $row["productid"]; ?>">Remove</a> </font> </td> </tr> <tr> <td width="100%" colspan="4"> <hr size="1" color="red" NOSHADE> </td> </tr> <tr> <td width="70%" colspan="2"> <font face="verdana" size="1" color="black"> <a href="home.php"><< Keep Shopping</a> </font> </td> <td width="30%" colspan="2"> <font face="verdana" size="2" color="black"> <b>Total: <?php echo number_format($totalCost, 2, ".", ","); ?> </b> </font> </td> </tr> </table> </body> </html> <?php } } ?> Code for a Sample Item which can be added to the Cart <?php include("menu.php"); include("SQL2.php"); $sql = mysql_query("SELECT * FROM product WHERE productid = '1'") or die(mysql_error()); $rows=mysql_fetch_array($sql); ?> <html> <head> <title>Core 2 Duo</title> <link rel="stylesheet" href="styler.css"> </head> <body> <br><br><br> <table border="0" width="87%" cellspacing="1" id="table1"> <tr> <td rowspan="6"> <img src="http://www.webuildsolutions.com/images/products/intel-core2duo-lga775-box.jpg"></td> <td width="398" colspan="2">Intel Core 2 Duo E6300</td> </tr> <tr> <td width="398" colspan="2"> </td> </tr> <tr> <td width="118">Clock Speed</td> <td width="277"> 3.72 GHz ( 2 X 1.86 GHz)</td> </tr> <tr> <td width="118">Bus Speed</td> <td width="277">1066 MHz</td> </tr> <tr> <td width="118">L2 Cache</td> <td width="277">2 MB </td> </tr> <tr> <td width="118">Features</td> <td width="277">Enhanced Speedstep Technology<br>Intel Extended Memory 64 Technology<br>Intel Virtualization Technology<br>Intel ViiV Technology</td> </tr> <tr> <td> <p align="center"> <i><p align="center"><? echo $rows['stock']; ?> in Stock </i> <p align="center">£ <? echo $rows['price']; ?> inc. VAT <a href ="cart.php?action=add_item@id=<?php echo $rows["productid"]; ?> &qty=1" > <img src = "add.jpg"> </a> </td> <td width="118">Warranty</td> <td width="277">3 Years</td> </tr> </table> <br><br><br> <?php include("base.php"); ?> </body> </html> Help is needed urgently. please help me out guys. Quote Link to comment https://forums.phpfreaks.com/topic/49472-eeeeeeeek-session-clashes/ Share on other sites More sharing options...
redarrow Posted May 1, 2007 Share Posted May 1, 2007 stick this on top of the page with the error <?php ob_start(); session_start(); //if session needed. ob_flush(); // end of page. ?> ob_start(); is not a good solution but will work ok. url http://uk3.php.net/ob_start Quote Link to comment https://forums.phpfreaks.com/topic/49472-eeeeeeeek-session-clashes/#findComment-242471 Share on other sites More sharing options...
OilSheikh Posted May 1, 2007 Author Share Posted May 1, 2007 One went away cos I decided to remove session( ) from within the code. Another remains. Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\ZSOFT\XAMPP\xampp\htdocs\menu.php: in C:\Program Files\ZSOFT\XAMPP\xampp\htdocs\SQL2.php on line 16 SQL2.PHP now looks like <?php ob_start(); mysql_connect ("localhost", "root" , "zforce") or die (mysql_error()); mysql_select_db("express") or die (mysql_error()); function GetCartId() { if (isset($_COOKIE["cartid"]) ) { return $_COOKIE["cartid"]; } else { setcookie("cartid",session_id(),time()+((3600*24)*2) ); return session_id(); } } ob_flush(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/49472-eeeeeeeek-session-clashes/#findComment-242765 Share on other sites More sharing options...
OilSheikh Posted May 1, 2007 Author Share Posted May 1, 2007 ??? Quote Link to comment https://forums.phpfreaks.com/topic/49472-eeeeeeeek-session-clashes/#findComment-242845 Share on other sites More sharing options...
OilSheikh Posted May 6, 2007 Author Share Posted May 6, 2007 Can NO-ONE HELP ME? :'( Quote Link to comment https://forums.phpfreaks.com/topic/49472-eeeeeeeek-session-clashes/#findComment-246706 Share on other sites More sharing options...
MadTechie Posted May 6, 2007 Share Posted May 6, 2007 post the menu script please first 10lines should be ok Quote Link to comment https://forums.phpfreaks.com/topic/49472-eeeeeeeek-session-clashes/#findComment-246710 Share on other sites More sharing options...
chronister Posted May 6, 2007 Share Posted May 6, 2007 You are trying to modify headers after the output has started. The output is starting on line 8 of menu.php. Take a look at the lines above it. Line 16 is the setcookie line. Menu.php is where the output is at to cause the error. Quote Link to comment https://forums.phpfreaks.com/topic/49472-eeeeeeeek-session-clashes/#findComment-246793 Share on other sites More sharing options...
OilSheikh Posted May 13, 2007 Author Share Posted May 13, 2007 Sorry about the late reply guys .. Damn flu kept me occupied. This is the latest only error that I get Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\ZSOFT\XAMPP\xampp\htdocs\cart.php:4) in C:\Program Files\ZSOFT\XAMPP\xampp\htdocs\SQL2.php on line 16 SQL2.PHP <?php ob_start(); mysql_connect ("localhost", "root" , "zforce") or die (mysql_error()); mysql_select_db("express") or die (mysql_error()); function GetCartId() { if (isset($_COOKIE["cartid"]) ) { return $_COOKIE["cartid"]; } else { setcookie("cartid",session_id(),time()+((3600*24)*2) ); return session_id(); } } ob_flush(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/49472-eeeeeeeek-session-clashes/#findComment-252005 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.