kenrbnsn Posted May 29, 2007 Share Posted May 29, 2007 Add <?php if (mysql_num_rows($sql) == 0) die("No rows found for " . $_SESSION['usern']); ?> before this statement: <?php $rows=mysql_fetch_assoc($sql) or die(mysql_error()); ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/53410-solved-this-is-weird/page/2/#findComment-264158 Share on other sites More sharing options...
per1os Posted May 29, 2007 Share Posted May 29, 2007 As long as the HTML is gone in the sql.php, that is a step in the right direction. You are missing a KEY factor in that code, you need session_start(); at the very top. The ob's are causing the problems with the session trust me. I suggest you figure out how to output information AFTER the header's and session data has been completed. The basics about session_start and header() and even setcookie, you cannot use them if data has ALREADY been sent to the browser. Using ob_start to "get around" that is half-assed solution and obviously does not work. Also there should be NO space between the top of the page and <?php or else that will throw the header/session error as output is already started. // SQL.PHP <?php mysql_connect ("localhost", "expresspc_***" , "***") or die (mysql_error()); mysql_select_db("expresspc_sql") or die (mysql_error()); ?> //ACC.PHP <?php session_start(); error_reporting(E_ALL); if(!session_is_registered('usern')) // always use single quotes around variables you are trying to reference, just good practice. { header("location:home.php"); } include("SQL.php"); include("menu.php"); $sql = mysql_query("SELECT * FROM customer WHERE username = '" . $_SESSION['usern'] . "'") or die(mysql_error()); $rows=mysql_fetch_assoc($sql) or die(mysql_error()); ?> <html> <head> <title>Your Account</title> <link rel="stylesheet" href="styler.css"> </head> <body> <br><br><br> <h1>MY ACCOUNT</h1> <br> <h3>Welcome to Your Account Area , <font size="5" color = blue><?php print $_SESSION[usern] ?> </font></h3> <br> <table border="0" width="101%" cellspacing="0" id="table1" bordercolorlight="#0066FF" height="130" cellpadding="0"> <tr> <td height="27" colspan="2"> <a href="acc.php"><img border="0" src="det2.jpg"></a> <a href="orders.php"> <img border="0" src="ord.jpg"></a> <a href="returns.php"> <img border="0" src="ret.jpg"></a></td> </tr> <tr> <td width="148" height="27"></td> <td width="593"> </td> </tr> <tr> <td width="148" height="27">Customer ID</td> <td width="593"> <? printf ("%04d", $rows['custid']); ?></td> </tr> <tr> <td width="148" height="27">First Name</td> <td height="27" width="593"> <? echo $rows['Firstname']; ?> </td> </tr> <tr> <td width="148" height="23">Surname</td> <td height="23" width="593"><? echo $rows['Surname']; ?></td> </tr> <tr> <td width="148" height="27">Delivery Address</td> <td width="593" height="27"><? echo $rows['address']; ?> * </td> </tr> <tr> <td width="148" height="26">Post Code</td> <td width="593" height="26"><? echo $rows['postcode']; ?> * </td> </tr> <tr> <td width="148" height="27">E-mail Address</td> <td width="593"><? echo $rows['email']; ?> * </td> </tr> </table> <br> <br> <a href="change.php"><img border="0" src="change.jpg"></a> <br><br> </p> </body> <?php include("base.php"); ?> </html> <?php session_start(); // this is always key when trying to use sessions on pages. 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 { ?> <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 } ?> Try that, nothing really beats coding properly. Quote Link to comment https://forums.phpfreaks.com/topic/53410-solved-this-is-weird/page/2/#findComment-264159 Share on other sites More sharing options...
OilSheikh Posted May 29, 2007 Author Share Posted May 29, 2007 kenrbnsn , tried what you said ... I get No rows found for - http://expresspc.110mb.com/page2.php frost, thanks for the rectified code. But, the header already sent error comes again Warning: Cannot modify header information - headers already sent by (output started at /www/110mb.com/e/x/p/r/e/s/s/p/expresspc/htdocs/menu.php: in /www/110mb.com/e/x/p/r/e/s/s/p/expresspc/htdocs/login.php on line 28 Quote Link to comment https://forums.phpfreaks.com/topic/53410-solved-this-is-weird/page/2/#findComment-264176 Share on other sites More sharing options...
per1os Posted May 29, 2007 Share Posted May 29, 2007 aye carumba. menu.php prints out data to the screen doesn't it? Line 11 does a header re-direct doesn't it? So logically the menu.php needs to be moved AFTER the header redirect line doesn't it? <?php session_start(); // this is always key when trying to use sessions on pages. 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 { include("menu.php"); // include the menu here to avoid the header message. ?> <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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/53410-solved-this-is-weird/page/2/#findComment-264181 Share on other sites More sharing options...
OilSheikh Posted May 29, 2007 Author Share Posted May 29, 2007 Error's gone. BUT ... nothing appears now after loggin in. Just the menu and blank space. ??? Changed back to $rows=mysql_fetch_array($sql); and I am then back at Square One. User Details still DO NOT show up. Quote Link to comment https://forums.phpfreaks.com/topic/53410-solved-this-is-weird/page/2/#findComment-264197 Share on other sites More sharing options...
per1os Posted May 29, 2007 Share Posted May 29, 2007 In the login, change this since now the session part should be corrected, right? if ($check2 == 1) { $_SESSION["usern"] = $usern; $_SESSION[''passw'] = $passw; header("location:acc.php"); } As long as the session guidance I suggested is obeyed that should now work. To verify it is working use the code ken provided. If that does not print out anything it means the session is still messing up. If it does not work post the current code with all updates you are using. Quote Link to comment https://forums.phpfreaks.com/topic/53410-solved-this-is-weird/page/2/#findComment-264205 Share on other sites More sharing options...
OilSheikh Posted May 29, 2007 Author Share Posted May 29, 2007 ;D :D FINAAAAAAAALLLLLLLLY, It works! Thanks very much Frost. All the more reason to be generous. PHPFreaks or you need a small payment from me. Quote Link to comment https://forums.phpfreaks.com/topic/53410-solved-this-is-weird/page/2/#findComment-264218 Share on other sites More sharing options...
per1os Posted May 29, 2007 Share Posted May 29, 2007 http://www.phpfreaks.com/forums/index.php/topic,45685.0.html give it to them. Quote Link to comment https://forums.phpfreaks.com/topic/53410-solved-this-is-weird/page/2/#findComment-264220 Share on other sites More sharing options...
OilSheikh Posted May 29, 2007 Author Share Posted May 29, 2007 I'll send something to both you and PHPFreak Quote Link to comment https://forums.phpfreaks.com/topic/53410-solved-this-is-weird/page/2/#findComment-264226 Share on other sites More sharing options...
OilSheikh Posted May 29, 2007 Author Share Posted May 29, 2007 Just one last thing, I have a Shopping Cart code which works perfectly. In that, Session registration is done , but this time, in the form of a cookie. If I first Login via login.php and then proceed to cart.php , which uses this session creation : session_start(); setcookie("cartid", session_id(), time() + ((3600 * 24) * 30)); return session_id(); will it cause any conflict ? Quote Link to comment https://forums.phpfreaks.com/topic/53410-solved-this-is-weird/page/2/#findComment-264228 Share on other sites More sharing options...
per1os Posted May 29, 2007 Share Posted May 29, 2007 Don't see why it would. Quote Link to comment https://forums.phpfreaks.com/topic/53410-solved-this-is-weird/page/2/#findComment-264232 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.