PHP + MYSQL Simple Chat Application (Part 2) - Chat Functions

preview_player
Показать описание

You may need to to view previous video in this series to get to this point.

This a follow on from the previous series, where I create the main functions for the application.

Thanks for watching.
Рекомендации по теме
Комментарии
Автор

Well, since you already have $db_name variable in your database connect file, you can just add "global db_name;" into your chat.func.php and then use $db_name in the $query variable because when i followed the video i named my database differently, i called mien ChatBox and not Chat, and so my script didnt work because i didnt realise in query you also put the actual database name :P. Anyways, Videos are very helpful, i jsut started on php so fun times XD Also, i hope vid comes soon :P Thanks!

NuclearPaws
Автор

Thanks, So you mean create a global variable, which will be used to connect to the database, as well as the query? I have integrated ajax using jQuery, to make it refresh and send with out refreshing the page, and will do a video on that shortly. Thanks for watching BTW, and hopefully these tutorials are of help to you. :)

IndexedWay
Автор

I believe you have mistype something in the query. This is the Query line used "SELECT `Sender`, `Message` FROM `chat`.`chat` ORDER BY `Msg_ID` DESC". If it still doesn't work. You can comment your script and I will have a look at it for you. It isn't an unusual error, I seem to get it a lot, due to the fact I have mistype something in the query or left something out. Thanks for watching.

IndexedWay
Автор

Thx a lot, very interesting, BUT im moving to ASP.NET, not because of you, because i cant get php in m, y mind, but thx for the extra help

ASP.NET Tutorials would be extremely helpful

waseemshahwan
Автор

Hi, Thanks for tutorial, its very helpful :) One thing I would suggest though is add global $db_name and use that in the $query = "SELECT `Sender`, `Message` FROM `".$db_name."`.`chat`"; This will cause less confusion and will make it a lot simpler if someone wants to use a different db_name. Could you make next tutorial on how to make the messages auto refresh every few seconds and how to make it so that when you refresh page it doesn't ask you to resend the form? Thanks :)

NuclearPaws
Автор

Sorry about the late reply, I have been caught up with other things. You should be able to just change the db_name is the database file, to the name of the database you want to connect too.

IndexedWay
Автор

Oh, and one more thing, do you really need to use jQuery for it? I'm not a big fan of using premade stuff but im just odd like that :3 And thanks for videos again :)

NuclearPaws
Автор

Thanks for watching, I just downloaded my script to a different computer which didn't have the database on it, and I got that error also. When I created a database 'chat' I also still got that error, cause I didn't have to the chat table created, so I created the table and still got the error. I figured out that I have used capitalisation in my script, so the tables in mysql will also have to have capitals in the right spaces. If this doesn't help, could you post your script and ill have a look.

IndexedWay
Автор

Hi I did exactly the same as you, but when the bag in boxes in place to defend how do you tie on your screen appears and the message of Luke, Luke appears instead of the Sender Sent the message appears instead of the Message what can I do to appear exactly as it appears.

ionliviumihai
Автор

i have downloaded your script and used all of the correct database names and everything but i get an error saying:
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in on line 11

please please help.thanks

SpacialGraphics
Автор

A question. Once the user logs in. Their previous conversations will ALWAYS be displayed. Since the content is stored in a database table. Is there any way to remedy that?

jeankaleb
Автор

Did you get the error fixed?

Thanks for watching, and I will see what happens.

IndexedWay
Автор

Im getting this error: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in on line 8, in which its : $query = "SELECT `Sender`, `Message` FROM `database`.`chat` ORDER BY `Msg_ID` DESC";
What am I doing wrong? :/

XIIIX
Автор

how do we upload it to a domain? I mean what do we put rather than 'localhost' when we upload in the domain ?

Gazzy-JUruj
Автор

The following scripts should be the ones used in this tutorials.

Chat.func.php

function get_msg() {

$query = "SELECT `Sender`, `Message` FROM `chat`.`chat`";

$run = mysql_query($query);

$messages = array();

while($message = mysql_fetch_assoc($run)) {
$messages[] = array('sender'=>$message['Sender'],

}

return $messages;

}

IndexedWay
Автор

Im getting this error and cant figure it out,
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in on line 11

waseemshahwan
Автор

I have a question i have a database named phpregister but i wana add a table in it named chat how can i connet to it

zstavba
Автор

I have a similar error with waseem, and I think I have done everything right.
but still this error comes out.

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in on line 11

Lexteriel
Автор

Connected to Database Server...
Database has been selected...
Message Failed to sent.

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in on line 6
HELP!

arahindon
Автор

If anyone is interested in the issue I posed (above or below.) All you would do to correct the problem is to run a delete query which would perpetually delete the contents of the chat table once the user navigates away from the chat.php page. If you are using sessions you would delete only the contents of the logged in user.

<?php
// The code below will delete the user and their conversation from the 'chat' table in the database if a user leaves the Chatroom page.
if($_SERVER['REQUEST_URI'] !== 'chat.php')
{
$queryreg_1 = mysql_query("DELETE FROM chat WHERE sender = '$user'");
}
?>

jeankaleb
visit shbcf.ru