PHP - Building Chat Database Ouput But Not Parsing Properly. Need Help.
Right,
First time on this site but hopefully I can figure out what im doing wrong. I am currently making a real time chat database for my website and have been having an issue with the coverting of string to emote image links. Code: [Select] function Smiley($texttoreplace) { $smilies=array( ':)' => "<img src='images/emotes/smile.gif'/>", ':(' => "<img src='images/emotes/sad.gif'/>", '>:(' =>"<img src='images/emotes/angry.gif'/>", ':o'=> "<img src='images/emotes/shocked.gif'/>", 'fuck'=>"$#$%", 'Fuck'=>"&$#@" ); $texttoreplace=strtr($texttoreplace, array_keys($smilies)); return $texttoreplace; } I Have even tried Code: [Select] $texttoreplace=str_replace(array_keys($smilies), array_values($smilies), $texttoreplace); but that didnt seem to work either. Here is my full code. Code: [Select] <?php include "connect.php"; $getnummessages="SELECT COUNT(*) as messagecount from chatmessages"; $getnummessages2=mysql_query($getnummessages) or die("Yay, Jump off cliff"); $getnummessages3= mysql_result($getnummessages2, 0); if($getnummessages3>21) { $startrow=$getmessages3-20; } else { $startrow=0; } $getmsg="SELECT name, message from chatmessages order by postime ASC limit $startrow,$getnummessages3"; $getmsg2=mysql_query($getmsg) or die(mysql_error()); while($getmsg3=mysql_fetch_array($getmsg2)) { $message=Smiley($message);//should make smiley here but not working....hmmmm print "<font color='red'><b>$getmsg3[name]:</b></font> $getmsg3[message]<br>"; } function Smiley($texttoreplace) { $smilies=array( ':)' => "<img src='images/smile.gif'>", ':angry' =>"<img src='images/angry.gif'>", ':o'=> "<img src='images/shocked.gif'>", 'fuck'=>"$#$%", 'Fuck'=>"&$#@" ); $texttoreplace=str_replace(array_keys($smilies), array_values($smilies), $texttoreplace); return $texttoreplace; } //this is my refresh script below ?> <script> setTimeout("window.location.replace('chatlog.php')",4000); </script> Any help would be great, been looking at this code for a while now so some fresh eyes would be great. Thanks, Score Similar TutorialsHello I have an array with data from `mysql` that I would like to output it in a table using twig. The image is an example of want i want to achieve but without any luck. `print_r` of the array data Array ( [Administrator] => Array ( [0] => Array ( [RoleName] => Administrator [PermissionName] => Catalog-View [PermissionId] => 1 ) [1] => Array ( [RoleName] => Administrator [PermissionName] => Catalog-Edit [PermissionId] => 2 ) [2] => Array ( [RoleName] => Administrator [PermissionName] => Catalog-Delete [PermissionId] => 3 ) ) [Moderator] => Array ( [0] => Array ( [RoleName] => Moderator [PermissionName] => Catalog-View [PermissionId] => 1 ) ) ) The `HTML` code: <table> <tr> <thead> <th>Controller - Action</th> {% for permission in permissions %} {% for item in permission %} <th>{{item.RoleName}}</th> {% endfor %} {% endfor %} </thead> </tr> {% for permission in permissions %} {% for item in permission %} <tr> <td>{{item.PermissionName}}</td> <td>{{item.PermissionId}}</td> </tr> {% endfor %} {% endfor %} </table> OUTPUT: <table> <tbody> <tr></tr> </tbody> <thead> <tr> <th>Controller - Action</th> <th>Administrator</th> <th>Administrator</th> <th>Administrator</th> <th>Moderator</th> </tr> </thead> <tbody> <tr> <td>Catalog-View</td> <td>1</td> </tr> <tr> <td>Catalog-Edit</td> <td>2</td> </tr> <tr> <td>Catalog-Delete</td> <td>3</td> </tr> <tr> <td>Catalog-View</td> <td>1</td> </tr> </tbody> </table> Later Edit MySQL Query: SELECT t3.PermissionName, t1.PermissionId, t2.RoleName FROM tbl_user_role_perm AS t1 INNER JOIN tbl_user_roles AS t2 ON t1.RoleId = t2.RoleId INNER JOIN tbl_user_permissions AS t3 ON t1.PermissionId = t3.PermissionId MySQL Dump: -- Dumping structure for table tbl_user_permissions CREATE TABLE IF NOT EXISTS `tbl_user_permissions` ( `PermissionId` int(11) NOT NULL AUTO_INCREMENT, `PermissionName` varchar(50) NOT NULL, `PermissionDescription` varchar(100) NOT NULL, PRIMARY KEY (`PermissionId`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1; -- Dumping data for table tbl_user_permissions: ~2 rows (approximately) DELETE FROM `tbl_user_permissions`; /*!40000 ALTER TABLE `tbl_user_permissions` DISABLE KEYS */; INSERT INTO `tbl_user_permissions` (`PermissionId`, `PermissionName`, `PermissionDescription`) VALUES (1, 'Catalog->View', 'View Catalog Method'), (2, 'Catalog->Edit', 'Edit Catalog Method'), (3, 'Catalog->Delete', 'Delete Catalog Method'); /*!40000 ALTER TABLE `tbl_user_permissions` ENABLE KEYS */; -- Dumping structure for table tbl_user_role CREATE TABLE IF NOT EXISTS `tbl_user_role` ( `UserRoleId` int(10) NOT NULL AUTO_INCREMENT, `UserId` int(10) NOT NULL, `RoleId` int(10) unsigned NOT NULL, PRIMARY KEY (`UserRoleId`), KEY `FK_tbl_user_role_tbl_user_roles` (`RoleId`), KEY `UserId` (`UserId`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1; -- Dumping data for table tbl_user_role: ~2 rows (approximately) DELETE FROM `tbl_user_role`; /*!40000 ALTER TABLE `tbl_user_role` DISABLE KEYS */; INSERT INTO `tbl_user_role` (`UserRoleId`, `UserId`, `RoleId`) VALUES (1, 13, 22), (2, 14, 22); /*!40000 ALTER TABLE `tbl_user_role` ENABLE KEYS */; -- Dumping structure for table tbl_user_roles CREATE TABLE IF NOT EXISTS `tbl_user_roles` ( `RoleId` int(10) unsigned NOT NULL AUTO_INCREMENT, `RoleName` varchar(50) NOT NULL, `CreatedDate` datetime NOT NULL, `ModifiedDate` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`RoleId`) ) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8; -- Dumping data for table tbl_user_roles: ~7 rows (approximately) DELETE FROM `tbl_user_roles`; /*!40000 ALTER TABLE `tbl_user_roles` DISABLE KEYS */; INSERT INTO `tbl_user_roles` (`RoleId`, `RoleName`, `CreatedDate`, `ModifiedDate`) VALUES (22, 'Administrator', '2014-10-28 09:53:08', NULL), (23, 'Moderator', '2014-10-28 09:53:13', NULL), (24, 'Admin', '2014-10-28 12:22:05', '2014-10-28 12:22:06'), (25, 'User', '2014-10-29 15:10:36', '2014-10-29 15:10:37'), (26, 'SuperUser', '2014-10-29 15:10:45', '2014-10-29 15:10:46'), (27, 'Accountant', '2014-10-29 15:10:53', '2014-10-29 15:10:54'), (28, 'God', '2014-10-29 15:11:02', '2014-10-29 15:11:02'); /*!40000 ALTER TABLE `tbl_user_roles` ENABLE KEYS */; -- Dumping structure for table tbl_user_role_perm CREATE TABLE IF NOT EXISTS `tbl_user_role_perm` ( `RoleId` int(10) unsigned NOT NULL, `PermissionId` int(10) unsigned NOT NULL, KEY `RoleId` (`RoleId`), KEY `PermissionId` (`PermissionId`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- Dumping data for table tbl_user_role_perm: ~3 rows (approximately) DELETE FROM `tbl_user_role_perm`; /*!40000 ALTER TABLE `tbl_user_role_perm` DISABLE KEYS */; INSERT INTO `tbl_user_role_perm` (`RoleId`, `PermissionId`) VALUES (22, 2), (22, 1), (23, 1), (22, 3); /*!40000 ALTER TABLE `tbl_user_role_perm` ENABLE KEYS */; /*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */; /*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;Can you help me to make the coding required so that the correct column have the correct permissions? thank you in advance. Hi, I was trying to build a chat room and tried the code given he http://www.codingmix.com/2010/12/privat ... mment-form but when i try to go to chat , sending is disabled and I cant chat Can anyone help? Also I want to create a room for chat like: based on a topic some more features like Adding a topic........and while chat choose the category like speaking for the topic, against or neutral and with option to post a point while chatting please help pooja_dubey12 Forum Newbie Posts: 3 Joined: Fri Jul 03, 2009 8:29 am Hello,
I want to know first, how to start new pages or small windows
Next, how to temporarily store data and then delete upon exit of chat so that memory can be saved
How to embed objects like images (objects?)
How to have resizable or set the size of input field for the message
Show a sign like "person is typing" when other person is inputting data
I'll probably get yelled at, I'm trying to amass all the information I need
I'll research each subject as I accomplish a task
Right now I could really use a download script that saves a photo, gets url of photo and searches the document for "By Name" and cuts out / stores the Name part and then renames the file with an increment of one, instead I have to do 300 clicks with my mouse. = ineptitude or ignorance
That is theoretically the ideal case but I have to sift through photos, see which ones are good eg. face is covered by watermark
Thanks for any help
Edited by greenace92, 02 December 2014 - 07:52 PM. Hi, I had a form which contains, 8 select boxes. In those 8 select boxes, 3 of the boxes are interlinked, like, I am able to generate data in other 2 select boxes, if one box is been selected. i.e. based upon selection of one select box, and i am able to generate data in other select box. So, 3 select boxes are interlinked. And remaining 5 selects are optional, if the user selects, then we need to generate data based upon selection of the user. Here the main issue is how to grab data in the post back form, like, how to capture the number of selects boxes selected and what are those selected, and based upon that we need to generate data. Here one more important thing is that, in the report generation form(postback form), I need to show the data in a table. So , in table I had 9 columns and these would be common to whatever the selection made, but, only the requeired data would be changed based upon the selection of the remaining 5 optional boxes. Hope you got me!!!! I am asking if anyone knows of any tutorials to take the contents of a simple form, hit submit, then the values go to an email, the email contents are then parsed and go into the correlating mysql table. For example, if I have a form like this http://nobaltimorebeveragetax.com/ It is only the first name, lastname, email address and zip code. I know how to do a POST or a GET, to put directly into a database table. The reason is because there are multiple sites with this type of form and would like them to go to one central database. I do not wish to do iframe since we would still have to style (css) each form. I have heard of "paring emails". Any tutorial, resources or suggestions would be most appreciated. Thanks Kip i am new with web socket
and in same time
I try to make server and client communication for soccer manager application, and for this purpose, i need to create closed "chat rooms" or "games" where two users can watch (read game event) and menage (create) game event (make substitution, formation ... or if you want, to send message to server, that they make changes in formation)
this game (room) mast bi secret, and only this two player can use this game for "read" and "write" events in game
for example: Game no: 200001 between user A and user B in 14.05.
when User A, and User B click on game no. 200001 they can read and write game event.
PS: for now, i create basic chat aplication with PHP, jQuery and webSocket and in this app, all user see wath all other user do (public chat) and i want to make secret chat for specific user (already automate subscribed from server) All work with no problem (i work on this example http://www.sanwebe.c...ket-php-socket)
How i can create chat room(s) and subscribe user to specific chat room?
Thanks
Edited by laponac84, 30 November 2014 - 09:09 AM. Hi, I have a MySQL database called "2011_database" that has a table called "2011_list." In that table I have fields, amongst others, called "name" and "district." I need to find way to get the data from the table and put them into a drop down list on other PHP page. But they need to be listed as "name - district" on one line. I am PHP beginner and if I understand it correctly there need to be two references to get all the data in all records, a third reference to merge them together with " - " in between; and what eludes me the most, putting them in a drop down menu. Any help is greatly appreciated Thanks HI, according to my knowledge session_destroy() function would destroy all session variables and mysql_close() would close connection with the database. i make a simply logoff.php file and close myssql connection and destroy session. but i still get values from the database and session variables. and doesnt work properly here is the code Code: [Select] <?php session_start(); /* * To change this template, choose Tools | Templates * and open the template in the editor. */ require_once '../database/db_connecting.php'; $dbname="sahansevena";//set database name $con= setConnections();//make connections use implemented methode in db_connectiong.php mysql_select_db($dbname, $con); //update the time and date of the admin table $update_time="update admin set last_logged_date =CURDATE(), last_log_time=CURTIME() where username='$uname'limit 3,4"; //my admin table contain 5 colums they are id, username,password, last_logged_date, last_log_time $link= mysql_query($update_time); // mysql_select_db($dbname, $link); //$con=mysql_connect('localhost', 'root','ijts'); $result="select * from admin where username='a'"; $result=mysql_query($result); mysql_close($con); //here i just check after closing data baseconnection whether i do get reselts but i do, why? echo "after the cnnection was closed"; echo "<html>"; echo "<table border='1' cellspacing='1' cellpadding='2' align='center'>"; echo "<thead>"; echo"<tr>"; echo "<th>"; echo ID; echo"</th>"; echo" <th>";echo Username; echo"</th>"; echo"<th>";echo Password; echo"</th>"; echo"<th>";echo Last_logged_date; echo "</th>"; echo "<th>";echo Last_logged_time; echo "</th>"; echo" </tr>"; echo" </thead>"; echo" <tbody>"; while($row= mysql_fetch_array($result,MYSQL_BOTH)){ echo "<tr>"; echo "<td>"; echo $row[0]; echo "</td>"; echo "<td>"; echo $row[1]; echo "</td>"; echo "<td>"; echo $row[2]; echo "</td>"; echo "<td>"; echo $row[3]; echo "</td>"; echo "<td>"; echo $row[4]; echo "</td>"; echo "</tr>"; } echo" </tbody>"; echo "</table>"; echo "</html>"; session_destroy(); session_commit(); echo "session and database are closed but i still get values".$_SESSION['admin']; ?> Hello to all, I have problem figuring out how to properly display data fetched from MySQL database in a HTML table. In the below example I am using two while loops, where the second one is nested inside first one, that check two different expressions fetching data from tables found in a MySQL database. The second expression compares the two tables IDs and after their match it displays the email of the account holder in each column in the HTML table. The main problem is that the 'email' row is displayed properly while its while expression is not nested and alone(meaning the other data is omitted or commented out), but either nested or neighbored to the first while loop, it is displayed horizontally and the other data ('validity', 'valid_from', 'valid_to') is not displayed.'
Can someone help me on this, I guess the problem lies in the while loop? <thead> <tr> <th data-column-id="id" data-type="numeric">ID</th> <th data-column-id="email">Subscriber's Email</th> <th data-column-id="validity">Validity</th> <th data-column-id="valid_from">Valid From</th> <th data-column-id="valid_to">Valid To</th> </tr> </thead> Here is part of the PHP code:
<?php while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo ' <tr> <td>'.$row["id"].'</td> '; while ($row1 = $stmt1->fetch(PDO::FETCH_ASSOC)) { echo ' <td>'.$row1["email"].'</td> '; } if($row["validity"] == 1) { echo '<td>'.$row["validity"].' month</td>'; }else{ echo '<td>'.$row["validity"].' months</td>'; } echo ' <td>'.$row["valid_from"].'</td> <td>'.$row["valid_to"].'</td> </tr>'; } ?>
Thank you. Hi Guys Somehow I can't make this chat work... maybe you've got an idea what the problem is? main.php <?php session_start(); ?> <html> <head> <title>Chat</title> <script language="JavaScript"> msg = new Array(); function showchat() { for (i = 0; i < msg.length; i++) { show.document.write(msg[i]; show.document.write("<br />"); } show.document.write("<a name='end'></a>"); } </script> </head> <frameset rows="0,*,45" border="0"> <frame name="main" src="main.php"> <frame name="show" src="show.php"> <frame name="send" src="send.php" scrolling="no"> </frameset> </html> <?php session_start(); $time = $_SESSION['time']; if (!isset($time)) $time = 0; $hdlDB = mysql_connect('localhost', 'root', ''); $strSQL = "SELECT * FROM chat WHERE time > '$curTime'"; $dhlRS = mysql_db_query('chat', $strSQL, $hdlDB); while ($arrRS = mysql_fetch_assoc($hdlRS)) { $arrMsg[] = '<b>' . $arrRS['sender'] . '</b>: ' . $arrRS['data']; $time = max($arrRS['time'], $time); } session_register('time'); ?> <html> <head> <title>Chat</title> <script language="JavaScript"> <?php if (is_array($arrMsg)) { $i = 0; foreach($arrMsg as $strLine) { echo "top.msg[$i] = '$strLine';\n"; $I++; } } ?> top.show.location.reload(); </script> </head> <body onload="window.setInterval('location.reload()', 4000)"> </body> </html> send.php <?php session_start(); if (!isset($time)) $time = 0; if (strlen($_POST['newmsg'] > 2) { $hdlDB = mysql_connect('localhost', 'root'; ''); $curTime = time(); $strSQL = "INSERT INTO chat (time, data, sender) VALUES ('$curTime', $newmsg', '$sender')"; mysql_db_query('chat', $strSQL, $hdlDB); session_register('time'); } /* end if */ ?> <html> <head> <title>Chat</title> <script language="JavaScript"> <?php if (is_array($arrMsg)) { foreach($arrMsg as $strLine) echo "top.msg[top.msg.length]=\"$strLine\""; } ?> top.show.location.reload(); </script> </head> <body bgcolor="white"> <form action="<?php echo $PHP_SELF; ?>" method="post"> <select name="sender" size="1"> <option value="Admin" <?php $sender == 'Admin' ? print 'selected' : print ''; ?>>Admin <option value="Client" <?php $sender == 'Client' ? print 'selected' : print ''; ?>>Client </select> 's Beitrag: <input type="Text" name="newmsg" size="40"> <input type="Submit" value="Send"> </form> </body> </html> show.php <html> <head> <title>Chat</title> </head> <body> <script language="JavaScript"> top.showchat(); </script> </body> </html> Database (chat) CREATE TABLE chat ( id bigint(20) NOT NULL auto_increment, time varchar(10) NOT NULL, data text, sender varchar(32) DEFAULT '1' NOT NULL, PRIMARY KEY (id), KEY id (id) ); cheers, ozzo Hi all im trying to build a chat like chathotel.http://chathotel.nl can someone help me out what the best way is to start ? I know php just trying to get it like this doesn’t get me on a start thanks would be great Edited May 29, 2019 by requinixunlinking Hi All... I am facing some problem while coding chat system.....my problem is that whenever i refresh the chat page the last message stored in the url by the current user displays again....its showing messages from the other users also but its keep on repeating the messages of the current user logged in,in the browser.....i am using post for all....do i need to try something else or any new way etc....if anybody have suggestions and solutions for the above mentioned problem then please do help me out...thank you... We want to add a chat feature in PHP for a social site can somebody suggest a good solution, a script maybe, where registered users when online can chat with other registered members in the friend list Hi i would like a simple chat page on my site for my members. i already have a site login database and want to know how i can let people chat and have their names entered with thier message without them having to login in to something else or typing their name with each message, for example - tom says: hello Hi, I'm trying to make an area where people can post stuff, status updates etc... I have a small layout done, but something has confused me. I'm trying to get it so when somebody is logged in, and posts something in the chat area, it displays: [Name] [Comment] I know how to read from the database, but for some reason, when I press the 'submit' button, the text in the 'comment' box isn't inserting into my 'comment' column in my database... But I want it so it inserts in the users column. Is this possible? Code: [Select] <?php if($submit) { $comment = $_POST['comment']; $submit = $_POST['submit']; $connect = mysql_connect("****","****","****") or die("Could not connect to database."); mysql_select_db("****") or die ("Could not find database!"); $query("INSERT INTO login ('comment') VALUES('$comment')"); $result = mysql_query($query) or die(mysql_error()); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form method="POST"> Comment: <input type="text" name="comment" /><br /> <input type="submit" name="submit" value="Submit" /><br /> </form> </body> </html> Can anyone suggest some good php Script(or Weburl) to do chat part in my php system please... Thanks in advance Hi, I need to develop a module called chat with doctor. User can able to chat with the doctor for that he has to pay some amount to website. Say example user got purchase the Package worth : 2$ =>5min. After 5 min chat will be closed , timer should be shown while chatting. How can we do this? I need free php chat module or script. Please tell me any known or good script. thanks I am not sure how I should go about doing this. I have a server that has a chat server on it, people register an account and then have access to this chat server from their application. To initially connect to it, they need a game id and game stamp (kind of like a username/password for the game). I don't want chats from one application to display in another users application. When I created this chat server it was for another purpose, and could only support about 64,510 different chats since each chat ran on its own port. For my current purpose it is a little different some applications can have 1 - 10 chats going at once per user using the application. Say their is 100 people using the application and each is using 5 - 10 different chat windows. With 100 users on at the same time all chatting, that can get up to 1,000 different ports being used. I don't want that, because say there are 100 applications also using chat, that is about 100,000 different ports, and I am pretty sure you cant have 100,000 ports. So! I need a way to make a chat server, any ideas on how I could do this with my php? need more information? please ask! I bought script for live chat support but i want something more. Now you can login with admin role and operator role, but what i want is to add user role so when user login in app he can see online operators and chat with them. It is open source so there is no legal issue..
So if anyone wants to help me i will send script on your email and try to solve this..
Thanks,Ivan
|