PHP/MySQLi Creating a Forum - Part 13 - User Page #3 - Sending Messages
Submitted by Yorkiebar on Tuesday, January 21, 2014 - 01:41.
Introduction:
This tutorial will be continuing my series of creating a forum in PHP/MySQLi/HTML. In this thirteenth part, We will be continuing our user page, more precisely, we will be adding a message form for the logged in user to contact the specified user.
Pre-creation:
First you will need a host for your PHP, either a web host or localhost is fine but you will need PHP and MySQL(i) capabilities.
Also, this will not be covering creating users, or styling the pages. For the purpose of using the logged in users username, we will be using $_SESSION['username']; from my login script, you can find that tutorial on my profile page.
Obviously you will also need to go through the first, second, third, fourth, fifth, sixth, seventh, eight, ninth, tenth, eleventh and twelfth parts of this tutorial series which can all be found on my profile tracking page.
User Page Editing:
First we need the HTML form for the contact function...
PHP:
Now for the actual sending PHP function/code. First we want to check if the messageSent post variable is set (that the submit button has been pushed), then we want to check and validate the title and message. If they are ok, we will add the information to our messages table within our forumTutorial database (created in the previous tutorial)...
Next Tutorial:
In the next tutorial, we will go over receiving messages.
- <br/>
- <h1>Contact</h1>
- <form <?php echo 'action="userPage.php?username='.$user.'"'; ?> method='POST'>
- <table>
- <tbody>
- <tr>
- <td>Message:</td><td><input type='text' name='message' /></td>
- </tr>
- <tr>
- <td></td><td><input type='submit' value='Send Message' name='messageSent' /></td>
- </tr>
- </tbody>
- </table>
- </form>
- $message = $_POST['message'];
- $from = $_SESSION['username'];
- $to = $_GET['username'];
- if ($q) {
- echo 'Message sent.';
- }else
- echo 'Failed to send message, contact the site administrator.';
- }
Comments
Add new comment
- Add new comment
- 59 views