Simple unregistered chat system on PHP

in #utopian-io7 years ago (edited)

PHP is well known server side language for web programming. Solutions of web needs, php is the language you can find resources on the web easily. Here in this contribution i will explain how to make "unregistered simple chat system" for your website.

First we have to create new database. I had named to my database as "simplechat".

Then we have to create new table. I had named it as "chat_msg".

ID is int autoincrement,
username is varchar,
msg is text
date is datetime 0

Before we start, you have to know that people will not register to this system. They will put their names, text whatever they want and we will add the date when they sent it.

Lets start code our html first of all.

<form method="post">
<input type="text" name="username" placeholder="Username">
<input type="text" name="message" placeholder="Write something...">
<input type="submit" name="send" value="Say it">
</form>

Basicly we just create some inputs needed from user.

Now lets start to code it in php;

In the picture as you can see, we create a connection to the database we already created.

Get data from inputs;

$username = $_POST['username'];
$message = $_POST['message'];

And then set the timezone, date type;

date_default_timezone_set("Europe/Berlin");
$datedate = date("Y/m/d/H/i/s");
``$error = false;` ( For not to get only msg or only username, always protect yourself by the error ).

Now we are done to get datas from user and insert into our database. Next step should be the show what is the users names and messages also when?

Created a loop to show what has ben sent already, order it by id and limited to 10 messages in a row. We had been set datetime to show which day month year hour etc.

Now lets add one more time;

If i couldnt fill the forms, there should be warn and no insert to the database,

I hope you enjoy and enlight to think how can you solve your issues quickly.

Have fun...

LOGO source : Source



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Your contribution cannot be approved yet. Although it doesn't directly violate one of our Utopian Rules, it has some issues that I'd really like to see fixed, to ensure a certain level of quality.

  • Please try to explain the code in more detail.
  • Please provide your code in a more accessible way. You can put the code directly into the post and use ```code``` to format it or provide public links to the code, for example on Pastebin or GitHub.
  • You don't explain all steps to follow your tutorial. (Database/PHPMyAdmin) Either add those steps or note what the requirements are to follow your tutorial, ideally with helpful links.
  • Your code is vulnerable to SQL injections: https://de.wikipedia.org/wiki/SQL-Injection Either fix the issues or note that this is insecure code only for example purpose.

Please edit your contribution to reapply for approval.

You may edit your post here, as shown below:

You can contact us on Discord.
[utopian-moderator]

Hey mkt, the changes you requested from me looks like a development contribution requirements. I add this contribute because it is tutorial to learn on php "how to do" basicly. The changes you wanted are pushing me to create new open source project by the github and change the type of contribution. According to me you are free to deny this contribution. Thanks for your check. Best wishes! :)

Your contribution cannot be approved because the requested changed where not implemented.

You can contact us on Discord.
[utopian-moderator]

Coin Marketplace

STEEM 0.19
TRX 0.13
JST 0.029
BTC 58000.61
ETH 3105.20
USDT 1.00
SBD 2.42