Question: Chat using a Database In this assignment you will be writing a simple chat program, where you can talk to yourself and see the message

Chat using a Database

In this assignment you will be writing a simple chat program, where you can talk to yourself and see the message history.

Step 1: You need to write a simple web page that will use PHP to run a single or multi-user chat program. Your page will have a small text box (input box), a large text box (history box) and a button. The input box is where you will type messages and the button will append what is in the input box (provided it isn't empty) to the history box. The chat data should be stored in a database table. Design the table in any way that you want. For a multi-user chat you will need to add a box for the users name. You could also provide time stamp information. You do not need to thread the discussions. Simply show the input line by line as it as type into the input textbox. When you save the chat messages in a database, they will appear the next time you go back to the page and chat again.

Code created so far:

index.php

Chat Box

style.css

body { padding: 35px; color: #222; font: 12px arial; text-align: center; }

form,p,span { margin: 0; padding: 0; }

input{ font: 12px arial; }

a{ color:#0000FF; text-decoration:none; }

a:hover{ text-decoration:underline; }

#wrapper, #loginform { margin:0 auto; padding-bottom:25px; background: #EBF4FB; width: 504px; border: 1px solid #ACD8F0; }

#loginform{ padding-top: 18px; }

#loginform p { margin: 5px; }

#chatbox { text-align: left; margin:0 auto; margin-bottom:25px; padding: 10px; background:#fff; height: 270px; width: 430px; border: 1px solid #ACD8F0; overflow: auto; }

#usermsg { width: 395px; border: 1px solid #ACD8F0; }

#submit { width: 60px; }

.error { color: #ff0000 }

#menu { padding: 12.5px 25px 12.5px 25px; }

.welcome { float:left; }

.logout { float: right; }

.msgin { margin:0 0 2px 0; }

login.php

session_start();

function loginForm(){ echo'

Enter your name to continue:

'; }

if(isset($_POST['enter'])) { if($_POST['name'] != "") { $_SESSION['name'] = stripslashes(htmlspecialchars($_POST['name'])); } else { echo 'Please type in a name again'; } } ?>

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!