Chat Place Style and design with PHP and MySQL

Chat Place Style and design with PHP and MySQL


In this posting, you will learn how to design and develop a basic online chat space with PHP and MySQL. This tutorial points out each measures of the enhancement, like both of those database layout and PHP programming. Basic computer system abilities and information of HTML and PHP are demanded. Okay, enable&#39s start now.

Stage 1: Design Databases Table. Produce desk “chat” in MySQL databases to retail store fundamental chat information and facts: chtime (chat time), nick (user nickname) and words (chat information, a lot less than 150 people)

mysql> Make Desk chat

-> chtime DATATIME,

-> nick CHAR (10) NOT NULL,

-> terms CHAR (150)

Phase 2: Style Framework. This uncomplicated online chat area features the adhering to 4 sections: consumer login, message display screen, message input and a most important body integrating the exhibit and enter sections. Thus, it needs the following four data files to work:

login.php

most important.php

screen.php

discuss.php

Stage 3: Publish the code

1. login.php (just a HTML sort)

<title> Person Login title&gt; </title>

Make sure you input your nickname and enter

<input type="text" name="nick" cols="20"> <input type="submit" value="login">

2. major.php

setcookie (“nick”, $ nick) // use cookie to retailer person nickname?>

<title> My Chat Space title&gt; </title> <frameset rows="80%,"> frameset&gt; </frameset> <frame src="display.php" name="chatdisplay"> <frame src="speak.php" name="speak">

3. exhibit.php

This file is utilized to get message documents from database and exhibit the benefits. To retain the size of databases, previous messages are deleted and only the newest 15 messages are shown.

<title> Exhibit Messages title&gt; </title> <meta http-equiv="refresh" content="5" url="https:" depth="1" amp hl="en" ie="UTF8" prev="_t" rurl="translate.google.com" sl="en" sp="nmt4" tl="en" u="https:" usg="ALkJrhgyQUNQTvHYQvWTB2YjSlUvwTUKZA">

// link to mysql server, server identify: main, database username: root

$ link_ID = mysql_connect (“principal”, “root”)

mysql_select_db (“abc”) // abc is the databases identify

$ str = “pick * from chat Purchase BY chtime”

$ outcome = mysql_query ($ str, $ hyperlink_ID)

$ rows = mysql_num_rows ($ end result)

// get the hottest 15 messages

@mysql_data_seek out ($ resut, $ rows-15)

// if the quantity of messages

}
// delete the previous messages (only hold the newest 20 only)

@mysql_info_find ($ result, $ rows-20)

list ($ limtime) = mysql_fetch_row ($ result)

$ str = “DELETE FROM chat The place chtime

4. speak.php

<title> Communicate title&gt; </title>

If ($ terms)

{$ link_ID = mysql_join (“principal”, “root”)

mysql_choose_db (“abc”) // abc is the database title

$ time = day (y) .day (m) .date (d) .date (h) .day (i). (day (s) // get latest time

$ str = “INSERT INTO chat (chtime, nick, terms) values
(&#39$ time&#39, &#39$ nick&#39, &#39$ words&#39) ”

mysql_question ($ str, $ url_ID) // conserve concept history into database

mysql_close ($ connection_ID)
)

?>

// the pursuing is the message input form

<input type="text" name="words" cols="20"> <input type="submit" value="Speak">

Now, you have concluded the structure and coding of a basic on the web chat technique. Put all the files into your web page root and see how it is effective, 🙂



Supply by Rory Canyons

Leave a Comment

Your email address will not be published. Required fields are marked *