Forum Tutorial - User Status and Signatures
Submitted by Yorkiebar on Sunday, March 2, 2014 - 08:44.
Introduction:
This tutorial will be on how to add status and signatures to user profiles. The status will show on their profile while their signature will show under their posts.
Database Updates:
We will need to store the information for both new features, so in our users table within our database we will add two new columns to the end of the structure:
status - VARCHAR - 255 Length
signature - VARCHAR - 255 Length
Editing Registration:
Because we add a new row to the users table on registration, we need to edit our query to take in to account the two new columns...
We leave the two end parameters blank because we want to the default status and signature for a new user account to be empty.
Settings:
The user will want to change their status and/or signature from time to time so we need to give them a way to do this. On the account/settings page where they are able to change their password, we want to add a new section to change their status, and another new section to change their signature. First we add the HTML...
Then we add the PHP code to process the HTML forms...
Posts (Signature):
Next we are going to display the users signature under their posts (threads and replies). First we need to grab the users signature from the database table, then we simply output it through HTML...
-From-:
-To-:
I have just appended it on to the end of the reply line, you may want to add it underneath but since I am not using CSS in these tutorials I have kept it simple.
- $qq = mysqli_query($con, "INSERT INTO `users` VALUES ('', '$user', '$passMD5', '$email', '0', '', '')");
- <?php
- $q = mysqli_query($con, "SELECT * FROM `users` WHERE `username`='$user'");
- $info = mysqli_fetch_array($q);
- ?>
- <form action='accountPage.php' method='POST'>
- <table>
- <tbody>
- <tr>
- </tr>
- <tr>
- </tr>
- </tbody>
- </table>
- </form>
- <?php
- $q = mysqli_query($con, "SELECT * FROM `users` WHERE `username`='$user'");
- $info = mysqli_fetch_array($q);
- ?>
- <form action='accountPage.php' method='POST'>
- <table>
- <tbody>
- <tr>
- </tr>
- <tr>
- </tr>
- </tbody>
- </table>
- </form>
- $status = $_POST['status'];
- if ($q) {
- echo 'Update completed successfully.';
- }else
- echo 'Failed to update user status.';
- }
- $sig = $_POST['sig'];
- if ($q) {
- echo 'Update completed successfully.';
- }else
- echo 'Failed to update user signature.';
- }
- $replies = '<table><tbody>';
- $replies .= '<tr><td>'.$row["content"].'</td><td>'.$row["author"].'</td></tr>';
- }
- $replies .= '</tr></tbody></table>';
- }
- $replies = '<table><tbody>';
- $author = $row["author"];
- $replies .= '<tr><td>'.$row["content"].'</td><td>'.$author.'</td><td>'.$repliedUser["signature"].'</td></tr>';
- }
- $replies .= '</tr></tbody></table>';
- }
Add new comment
- 48 views