PHP Chat Script - Set CHATDIR with value from variable
Place for comments, problems, questions, or any issue related to the JavaScript / PHP scripts from this site.
-
hups
- Posts:7
PHP Chat Script - Set CHATDIR with value from variable
hello,
i have a problem, i set the chatdir from database :
Code: Select all
define('CHATDIR', '../chattxt/'.$usernamerow.'/');
// the $usernamerow= 'hups';
when i set this the chat is not showing txt / dir is wrong.
when i set the name directly all is ok:
Code: Select all
define('CHATDIR', '../chattxt/hups/');
i must set the dir from database why is this wrong ??
sorry for bad english.
Admin
Posts:805
Hello
Your variable $usernamerow with the value added in CHATDIR must be defined before to set the CHATDIR constant.
Like in this example.
Code: Select all
$usernamerow = 'hups'; // here set its value with data from database
define('CHATDIR', '../chattxt/'. $usernamerow .'/');
hups
Posts:7
Thanks for help but this is not going . the chat show nothing.
when i write this:
Code: Select all
$userrow=$row['username'];
$user = ''.$userrow.'';
define('CHATDIR','chattxt/'.$user.'/');
the chat is false not showing Why ??
Admin
Posts:805
Apply this echo after CHATDIR to see what value /address contains:
The problem is not from the chat script, but from the way you get data from database.
Check what value has the variable $userrow or $user; with:
If it is null or false, the problem is in the code that gets data from database, or in the database table. For this, you can open a new topic (in the PHP-MySQL section) with that code and the problem you face with it.
hups
Posts:7
Code: Select all
$userrow=$row['username'];
$user = ''.$userrow.'';
define('CHATDIR','chattxt/'.$user.'/');
echo CHATDIR;
// show: chattxt/hups/
var_dump($userrow);
// show: string(4) "hups"
Admin
Posts:805
In a previous code, the path to "chattxt" directory was: "../chattxt/", now is without "../".
1. Check to have correct path to the "chattxt" directory according to the php file location.
2. In the "chattxt/" on server you must have the "hups/" folder (or what name is set in that variable) with writable permissions for php (CHMOD 0755, or 0777).
The cause can be an incorrect path, missing folder, or without writable permissions.
- If it works when you set the name directly, then it should work if the name it is from variable.
Admin
Posts:805
I made the Chat script to can be used with sub-folders in the "chattxt/" directory for chatrooms.
Download again the script from:
https://coursesweb.net/php-mysql/script-chat-simple_s2 , and test it.
In the Read.html file there is this note about sub-folder:
The "chattxt/" is the default directory in which the txt files with chatrooms are stored, but you can also use sub-folders added in "chattxt/" to store and use txt files.
- The sub-folder can be set in the $c_subdir variable (defined in "setchat.php" line 29), default is empty. This is useful if you want to use dinamically directory with chatrooms.
- The script creates automatically the sub-folder in "chattxt/", with the name added in $c_subdir and CHMOD 0755.