Create Simple Chatbox with Send Photo Feature Using PHP/MYSQL

Good day everyone! Today! I am going to teach on “CREATING A SIMPLE CHATBOX With SEND PHOTO FEATURE IN PHP/MYSQL”. 

This is for developers who wants to develop a website which is for communicating purposes. And this tutorial is a big help for them for starting up it.

Common tutorials in creating a chatbox are for posting only a message. But here, in my tutorial, I add a twist. You can now develop you simple chatbox in which users can post a message only, they can send a message with a photo or they can send or post photo only.

But before we start, make sure you already finished in developing your simple chatbox. I already have an article regarding this. And this may help you for starting up. Just >> click here << to visit my article.

Now if you are already done in the first step in developing your first simple chatbox. We can now add our added feature.

So first, just update the “index.php” file by putting the codes below.

include ‘connection.php’;
<!DOCTYPE html>
<meta charset=”UTF-8″>
<link rel=”stylesheet” href=”chat-style.css”>

Simple ChatBox Panel in PHP and MYSQL [ItSourceCode.Com]

Add Photo:

query(“SELECT * FROM chats ORDER BY chat_id DESC”);

num_rows; ?> total chats

fetch_assoc()) { ?>

”   s t y l e = ” w i d t h :   8 0 % ; ”  / >

<?php }

Then on the “post-chat.php” file, update it by putting the following codes.

include ‘connection.php’;
if (isset($_POST[‘post_chat’])) {
$name = $_POST[‘name’];
$msg = $_POST[‘msg’];
$date = date(“Y-m-d H:i:s”);
if ($_FILES[‘photo’][‘name’] == null) {
$chat = $mysqli->query(“INSERT INTO chats (chat_user, chat_msg, chat_time) VALUES (‘$name’, ‘$msg’, ‘$date’)”);
if ($chat) {
header(“Location: index.php”);
} else {
echo $mysqli->error;
} else {
move_uploaded_file($_FILES[‘photo’][‘tmp_name’], “photos/” . $_FILES[‘photo’][‘name’]);
$photo = “photos/” . $_FILES[‘photo’][‘name’];

$post = $mysqli->query(“INSERT INTO chats (chat_user, chat_msg, chat_photo, chat_time) VALUES (‘$name’, ‘$msg’, ‘$photo’, ‘$date’)”);
if ($post) {
header(“Location: index.php”);
} else {
echo $mysqli->error;


If you have questions about “Create Simple Chatbox w/ Send Photo Feature in PHP/MYSQL” feel free to ask us by commenting below or visit on our contact page. Thank you.

Related Article you may like:

Leave a Comment