Shaun13 Posted May 3, 2007 Share Posted May 3, 2007 Hi, this is a snipet from my newest project ShaunsBoards. It is some simple forum software. <? $tbl_name2="members"; $myusername=$_SESSION['myusername']; $mydn="SELECT displayname FROM $tbl_name2 WHERE username = '$myusername'"; $mydisplayname=mysql_query($mydn); if(session_is_registered(myusername)){ echo "Welcome ".$mydisplayname." | <a href='logout.php'>Logout</a>"; } else { echo "<a href='login.php'>Login</a> | <a href='register.php'>Register</a>"; } ?> This is a small snipet from my forums index. The $myusername variable is taken from the session cookie and that is in the mysql database. What I want it to do is get the persons username ($myusername) in the mysql table and get their display name which is also in that table. Now, when I leave it as "welcome.$myusername" it works fine, but right now I get this: Welcome Resource id #4 | Logout What am I doing wrong? ~Shaun Quote Link to comment Share on other sites More sharing options...
Shaun13 Posted May 3, 2007 Author Share Posted May 3, 2007 Anybody that could help me out with this would be lovely. Quote Link to comment Share on other sites More sharing options...
clown[NOR] Posted May 3, 2007 Share Posted May 3, 2007 first of all... please wait more than 5 minutes before bumping the topic.. now to the question... you could try using "Welcome $mydisplayname | <a href=\"logout.php\">Logout</a>"; or 'Welcome '.$mydisplayname.' | <a href="logout.php">Logout</a>'; maybe it will work... Quote Link to comment Share on other sites More sharing options...
Shaun13 Posted May 3, 2007 Author Share Posted May 3, 2007 Nope, sorry about double post too. When I use the variable $myusername instead of $mydisplayname it works fine. Is there a problem in the MySQL stuff? ~Shaun Quote Link to comment Share on other sites More sharing options...
clown[NOR] Posted May 3, 2007 Share Posted May 3, 2007 yes... i see what you mean now... $myusername get the value of the username session... but the $mydisplayname I'm not sure why it's not working... but that might be because I've never used that way to read from a DB yet sorry, but I'm gonna have to hand this over to someone else.. Good luck Quote Link to comment Share on other sites More sharing options...
john010117 Posted May 3, 2007 Share Posted May 3, 2007 Try this: <?php $tbl_name2="members"; $myusername=$_SESSION['myusername']; $mydn="SELECT displayname FROM $tbl_name2 WHERE username = '$myusername'"; $mydisplayname=mysql_query($mydn); if (mysql_num_rows($mydisplayname)>0) { while ($row = mysql_fetch_assoc($result)) { extract($row); if(session_is_registered(myusername)){ echo "Welcome ".$mydisplayname." | <a href='logout.php'>Logout</a>"; } else { echo "<a href='login.php'>Login</a> | <a href='register.php'>Register</a>"; } } } ?> Quote Link to comment Share on other sites More sharing options...
Shaun13 Posted May 3, 2007 Author Share Posted May 3, 2007 Nope, didn't work either. I got this: Welcome Resource id #4 | LogoutWelcome Resource id #4 | Logout Here is the PHP of the whole page: <?php session_start(); $host="localhost"; // Host name $username="=P"; // Mysql username $password="=P"; // Mysql password $db_name="=P"; // Database name $tbl_name="posts"; // 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"); $sql="SELECT * FROM $tbl_name ORDER BY id DESC"; // OREDER BY id DESC is order result by descending $result=mysql_query($sql); ?> <center> <?php $tbl_name2="members"; $myusername=$_SESSION['myusername']; $mydn="SELECT displayname FROM $tbl_name2 WHERE username = '$myusername'"; $mydisplayname=mysql_query($mydn); if (mysql_num_rows($mydisplayname)>0) { while ($row = mysql_fetch_assoc($result)) { extract($row); if(session_is_registered(myusername)){ echo "Welcome ".$mydisplayname." | <a href='logout.php'>Logout</a>"; } else { echo "<a href='login.php'>Login</a> | <a href='register.php'>Register</a>"; } } } ?> </center> <br /><br /> <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td width="40%" align="center" bgcolor="#CCDDCC"><strong>Topic</strong></td> <td width="20%" align="center" bgcolor="#CCDDCC"><strong>Author</strong></td> <td width="15%" align="center" bgcolor="#CCDDCC"><strong>Views</strong></td> <td width="13%" align="center" bgcolor="#CCDDCC"><strong>Replies</strong></td> <td width="13%" align="center" bgcolor="#CCDDCC"><strong>Date/Time</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ // Start looping table row ?> <tr> <td bgcolor="#FFFFFF"><a href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['title']; ?></a><BR></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['author']; ?></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['views']; ?></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['posts']; ?></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['datetime']; ?></td> </tr> <?php // Exit looping and close connection } mysql_close(); ?> <tr> <td colspan="5" align="right" bgcolor="#CCDDCC"> <? if(session_is_registered(myusername)){ echo "<a href='create_topic.php'><strong>Create New Topic</strong> </a>"; } else { echo "<a href='login.php'>Login</a> to start topics!"; } ?> </tr> </table> Quote Link to comment Share on other sites More sharing options...
john010117 Posted May 3, 2007 Share Posted May 3, 2007 Oh shoot. I forgot to change some variables. Sorry. <?php $tbl_name2="members"; $myusername=$_SESSION['myusername']; $mydn="SELECT displayname FROM $tbl_name2 WHERE username = '$myusername'"; $mydisplayname=mysql_query($mydn); if (mysql_num_rows($mydisplayname)>0) { while ($row = mysql_fetch_assoc($mydisplayname)) { extract($row); if(session_is_registered(myusername)){ echo "Welcome ".$mydisplayname." | <a href='logout.php'>Logout</a>"; } else { echo "<a href='login.php'>Login</a> | <a href='register.php'>Register</a>"; } } } ?> Quote Link to comment Share on other sites More sharing options...
Shaun13 Posted May 3, 2007 Author Share Posted May 3, 2007 Aww man. Still came up with the same thing. I will post both the login.php and index.php files. login.php: <!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>~ShaunsBoards~Login</title> </head> <center> <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <form name="form1" method="post" action="checklogin.php"> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCDDCC"> <tr> <td colspan="3" align="center"><strong><font color="#336633">ShaunsBoards Login </font></strong></td> </tr> <tr> <td width="78">Username</td> <td width="6">:</td> <td width="294"><input name="myusername" type="text" id="myusername"></td> </tr> <tr> <td>Password</td> <td>:</td> <td><input name="mypassword" type="password" id="mypassword"></td> </tr> <tr> <td> </td> <td> </td> <td><input type="submit" name="Submit" value="Login"> </td> </tr> <tr> <td align="center" colspan="4"><a href="register.php">Register</a></td> </tr> </table> </td> </form> </tr> </table><br /><br /><br /> </center> </body> </html> checklogin.php: <?php $host="localhost"; // Host name $username="=P"; // Mysql username $password="=P"; // Mysql password $db_name="=P"; // Database name $tbl_name="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 $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername"); session_register("mypassword"); session_register("myusername"); header("location:index.php"); $_SESSION['myusername']=$myusername; } else { echo "Wrong Username or Password"; } ?> index.php: <?php session_start(); $host="localhost"; // Host name $username="=P"; // Mysql username $password="=P"; // Mysql password $db_name="=P"; // Database name $tbl_name="posts"; // 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"); $sql="SELECT * FROM $tbl_name ORDER BY id DESC"; // OREDER BY id DESC is order result by descending $result=mysql_query($sql); ?> <center> <?php $tbl_name2="members"; $myusername=$_SESSION['myusername']; $mydn="SELECT displayname FROM $tbl_name2 WHERE username = '$myusername'"; $mydisplayname=mysql_query($mydn); if (mysql_num_rows($mydisplayname)>0) { while ($row = mysql_fetch_assoc($mydisplayname)) { extract($row); if(session_is_registered(myusername)){ echo "Welcome ".$mydisplayname." | <a href='logout.php'>Logout</a>"; } else { echo "<a href='login.php'>Login</a> | <a href='register.php'>Register</a>"; } } } ?> </center> <br /><br /> <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td width="40%" align="center" bgcolor="#CCDDCC"><strong>Topic</strong></td> <td width="20%" align="center" bgcolor="#CCDDCC"><strong>Author</strong></td> <td width="15%" align="center" bgcolor="#CCDDCC"><strong>Views</strong></td> <td width="13%" align="center" bgcolor="#CCDDCC"><strong>Replies</strong></td> <td width="13%" align="center" bgcolor="#CCDDCC"><strong>Date/Time</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ // Start looping table row ?> <tr> <td bgcolor="#FFFFFF"><a href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['title']; ?></a><BR></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['author']; ?></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['views']; ?></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['posts']; ?></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['datetime']; ?></td> </tr> <?php // Exit looping and close connection } mysql_close(); ?> <tr> <td colspan="5" align="right" bgcolor="#CCDDCC"> <? if(session_is_registered(myusername)){ echo "<a href='create_topic.php'><strong>Create New Topic</strong> </a>"; } else { echo "<a href='login.php'>Login</a> to start topics!"; } ?> </tr> </table> Feel free to change some things around and try. I really need this fixed. Thanks in advance. ~Shaun Quote Link to comment Share on other sites More sharing options...
john010117 Posted May 3, 2007 Share Posted May 3, 2007 I've just read that if you're using $_SESSION, don't use session_register(), session_is_registered, and session_unregister(). Read more about it here. Quote Link to comment Share on other sites More sharing options...
Shaun13 Posted May 3, 2007 Author Share Posted May 3, 2007 Ok, thanks for the tip. I only used $_SESSION because I don't know how to call session_register from the next page? Do you know? In other words, on index.php I have $myusername=$_SESSION['myusername']; How would i set up the variable for session register? Would it be: $myusername=sessionregister['myusername'] ??? ~Shaun Quote Link to comment Share on other sites More sharing options...
john010117 Posted May 3, 2007 Share Posted May 3, 2007 Like I said, don't use session_register. I rigged up a quick (hopefully working) solution for you. Also, NEVER put a password in a session. checklogin.php <?php $host="localhost"; // Host name $username="=P"; // Mysql username $password="=P"; // Mysql password $db_name="=P"; // Database name $tbl_name="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 $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" $_SESSION['myusername'] = $_POST['myusername']; header("location:index.php"); } else { echo "Wrong Username or Password"; } ?> index.php <?php session_start(); $host="localhost"; // Host name $username="=P"; // Mysql username $password="=P"; // Mysql password $db_name="=P"; // Database name $tbl_name="posts"; // 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"); $sql="SELECT * FROM $tbl_name ORDER BY id DESC"; // OREDER BY id DESC is order result by descending $result=mysql_query($sql); ?> <center> <?php $tbl_name2="members"; $myusername=$_SESSION['myusername']; $mydn="SELECT displayname FROM $tbl_name2 WHERE username = '$myusername'"; $mydisplayname=mysql_query($mydn); if (mysql_num_rows($mydisplayname)>0) { while ($row = mysql_fetch_assoc($mydisplayname)) { extract($row); if(session_is_registered(myusername)){ echo "Welcome ".$mydisplayname." | <a href='logout.php'>Logout</a>"; } else { echo "<a href='login.php'>Login</a> | <a href='register.php'>Register</a>"; } } } ?> </center> <br /><br /> <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td width="40%" align="center" bgcolor="#CCDDCC"><strong>Topic</strong></td> <td width="20%" align="center" bgcolor="#CCDDCC"><strong>Author</strong></td> <td width="15%" align="center" bgcolor="#CCDDCC"><strong>Views</strong></td> <td width="13%" align="center" bgcolor="#CCDDCC"><strong>Replies</strong></td> <td width="13%" align="center" bgcolor="#CCDDCC"><strong>Date/Time</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ // Start looping table row ?> <tr> <td bgcolor="#FFFFFF"><a href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['title']; ?></a><BR></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['author']; ?></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['views']; ?></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['posts']; ?></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['datetime']; ?></td> </tr> <?php // Exit looping and close connection } mysql_close(); ?> <tr> <td colspan="5" align="right" bgcolor="#CCDDCC"> <? if(isset($_SESSION['mysuername'])){ echo "<a href='create_topic.php'><strong>Create New Topic</strong> </a>"; } else { echo "<a href='login.php'>Login</a> to start topics!"; } ?> </tr> </table> Quote Link to comment Share on other sites More sharing options...
Shaun13 Posted May 3, 2007 Author Share Posted May 3, 2007 Ok, it got rid of the "Resource id #4, but now it doesn't say anything it just says: Welcome | Logout :'( ~Shaun Quote Link to comment Share on other sites More sharing options...
john010117 Posted May 3, 2007 Share Posted May 3, 2007 On that line, try: echo "Welcome $mydisplayname | <a href='logout.php'>Logout</a>"; Quote Link to comment Share on other sites More sharing options...
Shaun13 Posted May 3, 2007 Author Share Posted May 3, 2007 That seemed to have done something, but for some odd reason, it says: Welcome 0 | Logout Any ideas why? By the way thanks so much for helping me out, I appreciate it. ~Shaun Quote Link to comment Share on other sites More sharing options...
john010117 Posted May 3, 2007 Share Posted May 3, 2007 Put this in index.php and tell us what it outputs (I've put some error_messages in there just to get an idea where the code is going haywire). <?php session_start(); error_reporting(E_ALL); $host="localhost"; // Host name $username="=P"; // Mysql username $password="=P"; // Mysql password $db_name="=P"; // Database name $tbl_name="posts"; // 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"); $sql="SELECT * FROM $tbl_name ORDER BY id DESC"; // OREDER BY id DESC is order result by descending $result=mysql_query($sql); ?> <center> <?php $tbl_name2="members"; $myusername=$_SESSION['myusername']; $mydn="SELECT displayname FROM $tbl_name2 WHERE username = '$myusername'"; $mydisplayname=mysql_query($mydn); if (mysql_num_rows($mydisplayname)>0) { while ($row = mysql_fetch_assoc($mydisplayname)) { extract($row); if(session_is_registered(myusername)){ echo "Welcome ".$mydisplayname." | <a href='logout.php'>Logout</a>"; } else { echo "<a href='login.php'>Login</a> | <a href='register.php'>Register</a>"; } } } else { echo "You have encountered an error."; } ?> </center> <br /><br /> <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td width="40%" align="center" bgcolor="#CCDDCC"><strong>Topic</strong></td> <td width="20%" align="center" bgcolor="#CCDDCC"><strong>Author</strong></td> <td width="15%" align="center" bgcolor="#CCDDCC"><strong>Views</strong></td> <td width="13%" align="center" bgcolor="#CCDDCC"><strong>Replies</strong></td> <td width="13%" align="center" bgcolor="#CCDDCC"><strong>Date/Time</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ // Start looping table row ?> <tr> <td bgcolor="#FFFFFF"><a href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['title']; ?></a><BR></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['author']; ?></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['views']; ?></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['posts']; ?></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['datetime']; ?></td> </tr> <?php // Exit looping and close connection } mysql_close(); ?> <tr> <td colspan="5" align="right" bgcolor="#CCDDCC"> <? if(isset($_SESSION['mysuername'])){ echo "<a href='create_topic.php'><strong>Create New Topic</strong> </a>"; } else { echo "<a href='login.php'>Login</a> to start topics!"; } ?> </tr> </table> Quote Link to comment Share on other sites More sharing options...
Shaun13 Posted May 3, 2007 Author Share Posted May 3, 2007 Logged out I get: Notice: Undefined index: myusername in /var/www/=P/shaunsboards/index.php on line 21 You have encountered an error. Logged in I get: Notice: Use of undefined constant myusername - assumed 'myusername' in /var/www/=P/shaunsboards/index.php on line 27 Welcome Resource id #4 | Logout Whats it all mean, lol. ~Shaun Quote Link to comment Share on other sites More sharing options...
john010117 Posted May 3, 2007 Share Posted May 3, 2007 I forgot to replace session_is_registered. Durf! <?php session_start(); error_reporting(E_ALL ^ E_NOTICE); $host="localhost"; // Host name $username="=P"; // Mysql username $password="=P"; // Mysql password $db_name="=P"; // Database name $tbl_name="posts"; // 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"); $sql="SELECT * FROM $tbl_name ORDER BY id DESC"; // OREDER BY id DESC is order result by descending $result=mysql_query($sql); ?> <center> <?php $tbl_name2="members"; $myusername=$_SESSION['myusername']; $mydn="SELECT displayname FROM $tbl_name2 WHERE username = '$myusername'"; $mydisplayname=mysql_query($mydn); if (mysql_num_rows($mydisplayname)>0) { while ($row = mysql_fetch_assoc($mydisplayname)) { extract($row); if(isset($_SESSION['myusername'])){ echo "Welcome ".$mydisplayname." | <a href='logout.php'>Logout</a>"; } else { echo "<a href='login.php'>Login</a> | <a href='register.php'>Register</a>"; } } } else { echo "You have encountered an error."; } ?> </center> <br /><br /> <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td width="40%" align="center" bgcolor="#CCDDCC"><strong>Topic</strong></td> <td width="20%" align="center" bgcolor="#CCDDCC"><strong>Author</strong></td> <td width="15%" align="center" bgcolor="#CCDDCC"><strong>Views</strong></td> <td width="13%" align="center" bgcolor="#CCDDCC"><strong>Replies</strong></td> <td width="13%" align="center" bgcolor="#CCDDCC"><strong>Date/Time</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ // Start looping table row ?> <tr> <td bgcolor="#FFFFFF"><a href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['title']; ?></a><BR></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['author']; ?></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['views']; ?></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['posts']; ?></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['datetime']; ?></td> </tr> <?php // Exit looping and close connection } mysql_close(); ?> <tr> <td colspan="5" align="right" bgcolor="#CCDDCC"> <? if(isset($_SESSION['mysuername'])){ echo "<a href='create_topic.php'><strong>Create New Topic</strong> </a>"; } else { echo "<a href='login.php'>Login</a> to start topics!"; } ?> </tr> </table> Quote Link to comment Share on other sites More sharing options...
Shaun13 Posted May 3, 2007 Author Share Posted May 3, 2007 Here we go: ~Logged In~ Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /var/www/=P/shaunsboards/index.php:3) in /var/www/=P/shaunsboards/index.php on line 4 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /var/www/=P/shaunsboards/index.php:3) in /var/www/=P/shaunsboards/index.php on line 4 Welcome Resource id #4 | Logout ~Logged Out~ Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /var/www/=P/shaunsboards/index.php:3) in /var/www/=P/shaunsboards/index.php on line 4 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /var/www/=P/shaunsboards/index.php:3) in /var/www/=P/shaunsboards/index.php on line 4 You have encountered an error. Quote Link to comment Share on other sites More sharing options...
john010117 Posted May 3, 2007 Share Posted May 3, 2007 checklogin.php <?php session_start(); $host="localhost"; // Host name $username="=P"; // Mysql username $password="=P"; // Mysql password $db_name="=P"; // Database name $tbl_name="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 $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" $_SESSION['myusername'] = $_POST['myusername']; header("location:index.php"); } else { echo "Wrong Username or Password"; } ?> Quote Link to comment Share on other sites More sharing options...
Shaun13 Posted May 4, 2007 Author Share Posted May 4, 2007 same thing. :'( ~Shaun Quote Link to comment Share on other sites More sharing options...
john010117 Posted May 4, 2007 Share Posted May 4, 2007 Fixed some spelling errors, and changed a few things. index.php <?php session_start(); error_reporting(E_ALL ^ E_NOTICE); $host="localhost"; // Host name $username="=P"; // Mysql username $password="=P"; // Mysql password $db_name="=P"; // Database name $tbl_name="posts"; // 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"); $sql="SELECT * FROM $tbl_name ORDER BY id DESC"; // OREDER BY id DESC is order result by descending $result=mysql_query($sql); ?> <center> <?php $tbl_name2="members"; $myusername=$_SESSION['myusername']; $mydn="SELECT displayname FROM $tbl_name2 WHERE username = '$myusername'"; $mydisplayname=mysql_query($mydn); if (mysql_num_rows($mydisplayname)>0) { while ($row = mysql_fetch_assoc($mydisplayname)) { extract($row); if(isset($_SESSION['myusername'])){ echo "Welcome , $myusername | <a href='logout.php'>Logout</a>"; } else { echo "<a href='login.php'>Login</a> | <a href='register.php'>Register</a>"; } } } else { echo "You have encountered an error."; } ?> </center> <br /><br /> <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td width="40%" align="center" bgcolor="#CCDDCC"><strong>Topic</strong></td> <td width="20%" align="center" bgcolor="#CCDDCC"><strong>Author</strong></td> <td width="15%" align="center" bgcolor="#CCDDCC"><strong>Views</strong></td> <td width="13%" align="center" bgcolor="#CCDDCC"><strong>Replies</strong></td> <td width="13%" align="center" bgcolor="#CCDDCC"><strong>Date/Time</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ // Start looping table row ?> <tr> <td bgcolor="#FFFFFF"><a href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['title']; ?></a><BR></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['author']; ?></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['views']; ?></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['posts']; ?></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['datetime']; ?></td> </tr> <?php // Exit looping and close connection } mysql_close(); ?> <tr> <td colspan="5" align="right" bgcolor="#CCDDCC"> <? if(isset($_SESSION['myusername'])){ echo "<a href='create_topic.php'><strong>Create New Topic</strong> </a>"; } else { echo "<a href='login.php'>Login</a> to start topics!"; } ?> </tr> </table> Quote Link to comment Share on other sites More sharing options...
Shaun13 Posted May 4, 2007 Author Share Posted May 4, 2007 Thanks much, I think we are much closer, but it says: Welcome shaun | Logout shaun is my username and Shaun is my display name... Can it be fixed? ~Shaun Quote Link to comment Share on other sites More sharing options...
john010117 Posted May 4, 2007 Share Posted May 4, 2007 Is mydisplayname a field name in your database? Quote Link to comment Share on other sites More sharing options...
Shaun13 Posted May 4, 2007 Author Share Posted May 4, 2007 Yup, heres a screeny: ~Shaun 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.