PHP Chatbox

Around 2 years ago my friend coded a PHP Chatbox which I did the design for.

Im currently trying to use it howver login/register doesnt work and you can post messages… :confused:

I have no idea why… I only coded the database connection from what I can see works fine

Here is the project

I think your problem is in your doLogin.php

In this routine you select all the distinct name from the users table

[php]//Get currently in use usernames based on latest posts
$names = array();
if($query = $con->query(“SELECT DISTINCT name FROM users”)){
while($result = $query->fetch_assoc()){
$names[$result[‘poster’]] = $result[‘poster’];
}
}[/php]

But you don’t reference the name column, you reference “poster” that’s not part of your query.

It should most likely be this…

[php]//Get currently in use usernames based on latest posts
$names = array();
if($query = $con->query(“SELECT DISTINCT name FROM users”)){
while($result = $query->fetch_assoc()){
$names[$result[‘name’]] = $result[‘name’];
}
}[/php]

I tried that. Still cant seem to login and post on the chat

Without me downloading it and stepping through the code - It’s very hard to debug to say where the problem is.

What I pointed out is an issue.

Get a php IDE load up the project in it and step through the code and you’ll quickly understand which part(s) is preventing it from working right.

Go through this post there are many suggestions on IDE’s you can use.

http://www.phphelp.com/forum/beginners-learning-php/whats-the-best-php-editor-that-anyone-would-recommend/

Once you get an IDE and figure out where it breaks down, then I’ll be able to help you a little more.

A couple things.

Your DB should be setup to not allow duplicate usernames so there should be no need for DISTINCT in your query.

MD5 is no good for passwords. Use Bcrypt.

You need to use prepared statements. You are sending user input directly to the database. The app is insecure.

You are setting session data with user supplied data. Very bad.

Sponsor our Newsletter | Privacy Policy | Terms of Service