Jump to content

john010117

Members
  • Posts

    492
  • Joined

  • Last visited

    Never

Everything posted by john010117

  1. Strange... try this: <?php error_reporting(E_ALL); $user = $_POST['user']; echo "Username: $user"; ?> and see if you get any error messages.
  2. 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 , $displayname | <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> This should work. But I see that you didn't put any kind of security measures in your code. Read this after you get your code to work.
  3. What exactly is the output? Does it at least echo "Username:"?
  4. Is mydisplayname a field name in your database?
  5. Sessions. Read more about them here
  6. Script.php <?php $user = $_POST['user']; echo "Username: $user"; ?> Don't put a space between $_POST and ['user'].
  7. 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>
  8. It means to replace that with the string you are looking for.
  9. 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"; } ?>
  10. I don't believe you are really protected from MySQL Injections. Read this article.
  11. 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>
  12. What job? Please elaborate, and post some code if necessary.
  13. Maybe you should put an index or a key in one of the fields...
  14. 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>
  15. Some people are just way too lazy to convert their websites from HTML tables to CSS. I'm in the process of making one myself.
  16. You've posted this in the wrong section. Just upload it to your webhost (assuming that you have one). PS: You do realize that you're code will not work, right?
  17. You should make a login page, and use sessions to validate the user (which I think you're doing).
  18. On that line, try: echo "Welcome $mydisplayname | <a href='logout.php'>Logout</a>";
  19. Please elaborate on your question. I don't quite get what you're asking. If you want an admin to log in first, use sessions.
  20. 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>
  21. Post your code here so we can take a look at it (before you start pulling your hair out). Since I've recently formatted my hard disk (of a nasty virus), I don't have any mp3's yet.
  22. 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.
  23. First of all, please wait at least an hour before double posting. We all have lives, you know. Second of all, care to elaborate on your problem?
  24. I've never heard that happening before. Check your script again.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.