Snooble Posted January 30, 2007 Share Posted January 30, 2007 Hello people,I want to show the user his/her name once logged in. The log in works fine but it's creating the session variables that i need to do. And also i need to know what to put at the top of every page of my site. session_start(); and what else. The idea is so i can create an if statement. Something like[code]<?phpif($_SESSION['myemail']){;echo "You are logged in/n Click here to log out"}else{echo "Click here to log in /n Click here to register"}?>[/code]When i do run a statement like that i will ALWAYS recieve the else statement. eg. Click here to log in /n Click here to registerSo i assume i'm not carrying variables or possibly not carrying sessions? Thank you for looking. Pages beneath are my login form, my check login, and my registration form."login.php"[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title><style type="text/css"><!--.style21 {font-family: ADMUI3Lg, serif, monospace, cursive; font-weight: bold; font-size: 16px; color: #FFFFFF; }body { margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px;}.style22 { color: #000000; font-size: 14px;}.style25 {font-size: 9px; color: #fbedc7; }.style26 {font-size: 14px}.style27 {color: #fbedc7}.style28 {color: #000000}.style29 { font-size: 10px; color: #FF0000;}.style30 {font-size: 9px}.style31 { font-size: 11px; color: #CCCCCC;}.style32 {font-size: 1px}.style34 {color: #000000; font-size: 12px; }.style36 {font-size: 13px}.style37 { color: #FFFFFF; font-size: 1px;}--></style></head><body> <form method="post" action="checklogin.php"><table width="100%" height="100%" border="0"> <tr> <td height="25" background="Untitled-4.gif"><div align="center"><span class="style21">Login </span></div></td> </tr> <tr> <td valign="top"><table width="100%" height="0%" border="0" cellpadding="0" cellspacing="0"> <tr> <td height="5" colspan="4" valign="top"><span class="style37">.</span></td> </tr> <tr> <td height="21" colspan="4" valign="top" background="fbedc7.gif"> </td> </tr> <tr> <td width="552" height="56%" valign="middle" background="fbedc7.gif"><div align="right"><span class="style22"> Email Address </span><span class="style26"><br /> <span class="style27">s</span><br /> <span class="style28">Passwor<span class="style22">d</span><span class="style22"> </span><span class="style22"> </span> </span></span></div></td> <td width="5" valign="top" background="fbedc7.gif"> </td> <td width="375" valign="top" background="fbedc7.gif"><input type="text" name="myemail" /> <br /> <span class="style25"> s </span> <br /> <input type="password" name="mypassword" /></td> <td valign="top" background="fbedc7.gif"> </td> </tr> <tr> <td height="12%" align="center" valign="middle" background="fbedc7.gif"><div align="right"><span class="style30"><span class="style31">Remember Me</span> <input name="radiobutton" type="radio" value="radiobutton" /> </span></div></td> <td height="12%" colspan="2" align="center" valign="middle" background="fbedc7.gif"><span class="style29"><a href="retrievepassword.php">Forgot Your Password?</a></span></td> <td width="294" valign="top" background="fbedc7.gif"><div align="center"> <input type="submit" name="Submit" value="Login"> </div></td> </tr> <tr> <td height="8" colspan="4" align="center" valign="middle" bgcolor="#FFFFFF"><span class="style37">a</span></td> </tr> <tr> <td height="25" colspan="4" align="center" valign="middle" background="Untitled-4.gif"><span class="style21">Security Notice </span></td> </tr> <tr> <td height="4" colspan="4" align="center" valign="middle" bgcolor="#FFFFFF"><span class="style32"> a </span></td> </tr> <tr> <td height="110" colspan="4" align="center" valign="middle" background="fbedc7.gif" bgcolor="#FFFFFF"><div align="left" class="style34"> <div align="center"><span class="style27">.</span><br /> <span class="style36">1. Look for http://www.onetimedeals.co.nr in the URL box.<br /> <br /> 2. Never give out your password to anyone. We will never ask for it, EVER.<br /> <br /> 3. If you feel you are not secure on our site at any time please ring us immeadiatly.</span><br /> <br /> <br /> </div> </div></td> </tr> <tr> <td height="8" colspan="4" align="center" valign="middle" bgcolor="#FFFFFF"> </td> </tr> </table> <br /> <br /> <br /> <br /></td> </tr></table></form><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /></body></html>[/code]checklogin.php[code]<?php$host="**********"; // Host name$username="********"; // Mysql username$password="********"; // Mysql password$db_name="***********"; // Database name$tbl_name="web_members"; // Table name// Connect to server and select databse.mysql_connect("$host", "$username", "$password")or die("cannot connect");mysql_select_db("$db_name")or die("cannot select DB");// username and password sent from signup form$myemail=$_POST['myemail'];$mypassword=$_POST['mypassword'];$sql="SELECT * FROM $tbl_name WHERE Email='$myemail' and Password='$mypassword'";$result=mysql_query($sql);// Mysql_num_row is counting table row$count=mysql_num_rows($result);// If result matched $myemail and $mypassword, table row must be 1 rowif($count==1){// Register $myusername, $myemail and redirect to file "login_success.php"$_SESSION['myemail'] = $myemail;$_SESSION['mypassword'] = $mypassword;$_SESSION['fname'] = $fname;$_SESSION['sname'] = $sname;$_SESSION['addno'] = $addno;$_SESSION['addone'] = $addone;header("location:index.php");}else {echo "Wrong Username or Password";}?>[/code]Registration Page[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Secure :: One Time Deals :: Register </title><style type="text/css"><!--.style21 {font-family: ADMUI3Lg, serif, monospace, cursive; font-weight: bold; font-size: 16px; color: #FFFFFF; }body { margin: 0px; padding-top: 2px; padding-right: 2px; padding-bottom: 4px; padding-left: 2px; background-image: url(fbedc7.gif);}.style37 { color: #FFFFFF; font-size: 1px;}.style38 {color: #CCCCCC}--></style></head><body><table width="100%" height="19%" border="0" background="fbedc7.gif"> <tr> <td height="25" background="Untitled-4.gif"><div align="center"><span class="style21">Register</span></div></td> </tr> <tr> <td height="131" valign="top" background="fbedc7.gif"><table width="100%" height="0%" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="100%" height="1" valign="top"><span class="style37">.</span></td> </tr> <tr> <td height="33" align="center" valign="middle" background="fbedc7.gif" bgcolor="fbedc7"><div align="center"><span xmlns:sitefunctions="urn:siteFunctions"> </span><img src="shoppingbasketheader.gif" alt="Shopping Basket" xmlns:sitefunctions="urn:siteFunctions" align="absmiddle" height="24" width="215" /> </div></td> </tr> <tr> <td height="8" valign="top" bgcolor="#FFFFFF"><div align="center"><span class="style37">.</span></div></td> </tr> <tr> <td height="11" valign="top" background="fbedc7.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="898" background="fbedc7.gif" bgcolor="fbedc7"><div align="center"> <br /> <span class="style38"><?php echo $_POST["fname"]; ?> <?php echo $_POST["sname"]; ?>, Welcome To One Time Deals</span><br /> </div> <br /> <?php $host="********"; // Host name$username="********"; // Mysql username$password="*****"; // Mysql password$db_name="*******"; // Database name$tbl_name="web_members"; // Table name// Connect to server and select databse.echo '<form action="index.php" method="post"> <input type="hidden" name="email" value="'.$_POST['email'].'"> <input type="hidden" name="fname" value="'.$_POST['fname'].'"> <input type="hidden" name="sname" value="'.$_POST['sname'].'"> <input type="hidden" name="pass" value="'.$_POST['pass'].'"> <input type="hidden" name="passtwo" value="'.$_POST['passtwo'].'"> <input type="hidden" name="llno" value="'.$_POST['llno'].'"> <input type="hidden" name="mobno" value="'.$_POST['mobno'].'"> <input type="hidden" name="addno" value="'.$_POST['addno'].'"> <input type="hidden" name="addone" value="'.$_POST['addone'].'"> <input type="hidden" name="addtwo" value="'.$_POST['addtwo'].'"> <input type="hidden" name="addthree" value="'.$_POST['addthree'].'"> <input type="hidden" name="city" value="'.$_POST['city'].'"> <input type="hidden" name="other" value="'.$_POST['other'].'"> <input type="hidden" name="country" value="'.$_POST['country'].'"> <input type="hidden" name="noc" value="'.$_POST['noc'].'"> <input type="hidden" name="ccno" value="'.$_POST['ccno'].'"> <input type="hidden" name="expdate" value="'.$_POST['expdate'].'"> <input type="hidden" name="cvv" value="'.$_POST['cvv'].'"> <input type="image" src="register.gif" name="submit" alt="Log In" value="Log In" />'; mysql_connect("$host", "$username", "$password") or die ("cannot connect: " . mysql_error());mysql_select_db("$db_name") or die("cannot select DB: " . mysql_error());$sql = "INSERT INTO web_members (Email, Password, Firstname, Surname, AddNo, AddOne, AddTwo, AddThree, City, Country, Other Country, NOC, CCNO, ExpDate, ExpDatey, CVV) VALUES ('".$_POST['email']."', '".$_POST['pass']."', '".$_POST['fname']."', '".$_POST['sname']."', '".$_POST['addno']."', '".$_POST['addone']."', '".$_POST['addtwo']."', '".$_POST['addthree']."', '".$_POST['city']."', '".$_POST['country']."', '".$_POST['other']."', '".$_POST['noc']."', '".$_POST['ccno']."', '".$_POST['expdate']."', '".$_POST['cvv']."')";mysql_query($sql) or die ("Couldn't execute $sql: " . mysql_error());?> </td> </tr> </table> <div align="center"></div></td> </tr> <tr> <td height="19" align="center" valign="middle" background="fbedc7.gif" bgcolor="#FFFFFF"><span class="style37">a</span></td> </tr> </table> </td> </tr></table></body></html>[/code]Now you can have a good look at the site and what i want to achieve.I just want the fields to be carried around the site at all times when they are logged in. I will make a log out button using session_destroy();Thank you and i hope this information makes it clearer.Snooble Quote Link to comment Share on other sites More sharing options...
tauchai83 Posted January 30, 2007 Share Posted January 30, 2007 putting only session_start(); on very top of pages does not help if u do not register the variable. You may use setcookie function to echo it if u want...so tat it looks more "personalized" to user...:) check it out in this forum wheteher this prob has been encountered b4 and solved here...regards,chai Quote Link to comment Share on other sites More sharing options...
Snooble Posted January 30, 2007 Author Share Posted January 30, 2007 Right. The information i need is in the mysql table. When someone is logged in. I want to be able to access the rest of the information in the row. Egtable looks likeemail password address no. address street county/state country .etcwhen they log in with "email" and "password" how can i print their address to them? Snooble Quote Link to comment Share on other sites More sharing options...
tauchai83 Posted January 30, 2007 Share Posted January 30, 2007 is just like retriving data using mysql_fetch_array or mysql_fectch_assoc or u may list it aslist ($userid, $useraddress, $phone, $email )= mysql_fetch_array("select * FROM user where username=$userid"); Quote Link to comment Share on other sites More sharing options...
Snooble Posted January 30, 2007 Author Share Posted January 30, 2007 ok i'll give it a go now :)thank youSNooble Quote Link to comment Share on other sites More sharing options...
Snooble Posted January 30, 2007 Author Share Posted January 30, 2007 I get a blank page trying to echo$_SESSION['myemail'];or$myemailI want this page to echo the users email:[code]<?// Check if session is not registered , redirect back to main page.// Put this code in first line of web page.session_start();if(!session_is_registered(myemail)){header("location:loginotd.php");}else{list ($myemail, $mypassword, $fname, $sname )= mysql_fetch_array("select * FROM web_members where Email=$myemail");echo "";}?>[/code]Here is the login check:[code]<?php$host="**********"; // Host name$username="********"; // Mysql username$password="********"; // Mysql password$db_name="********"; // Database name$tbl_name="web_members"; // Table name// Connect to server and select databse.mysql_connect("$host", "$username", "$password")or die("cannot connect");mysql_select_db("$db_name")or die("cannot select DB");// username and password sent from signup form$myemail=$_POST['myemail'];$mypassword=$_POST['mypassword'];$sql="SELECT * FROM $tbl_name WHERE Email='$myemail' and Password='$mypassword'";$result=mysql_query($sql);// Mysql_num_row is counting table row$count=mysql_num_rows($result);// If result matched $myemail and $mypassword, table row must be 1 rowif($count==1){// Register $myusername, $myemail and redirect to file "login_success.php"$_SESSION['myemail'] = $myemail;$_SESSION['mypassword'] = $mypassword;$_SESSION['fname'] = $fname;$_SESSION['sname'] = $sname;$_SESSION['addno'] = $addno;$_SESSION['addone'] = $addone;header("location:login_success.php");}else {echo "Wrong Username or Password";}?>[/code]Someone, Please!???? Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 30, 2007 Share Posted January 30, 2007 you're using mysql_fetch_array() wrong. Turn on error reporting! Quote Link to comment Share on other sites More sharing options...
Snooble Posted January 30, 2007 Author Share Posted January 30, 2007 how would i do that? ApologiesSnooble Quote Link to comment 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.