Username:
Password:
Remember me:
Register

Back to forum: Web Programming (HTML, JS, CSS, PHP, MySQL)


Search forums via Google


0 Users appreciate this thread.

how to make commands like in chats
Started by PLMasterSSB
(2014-05-31 20:10:10)
PLMasterSSB (2014-05-31 20:10:10)
ill assume you already have chat. I prefer ajax with the chat.

so what you do is decide what your code is gonna be. then decide how its gonna operate (Example: /ban PLMasterSSB 2 day)

then you get the variable of your text box in the chat: $text

then your gonna use the substr() and explode() function:



<?php
if(substr($text, 0, 4) == "/ban" {
$substrvari = substr($text, 5);
// checks if there is text starting from the 5th character
$explode = explode(" ", $substrvari);
// explodes every set of words starting from the 5th character
//name the variables now
// PLMasterSSB
$explode2 = $explode[0];
// interger
$explode3 = $explode[1];
// time measure
$explode4 = $explode[2];

// but then if you were gonna do the ban command like above you need to use the NOW() and DATE_ADD function

MySQL_query("UPDATE register SET banneduntil=DATE_ADD(banneduntil, INTERVAL interger TimeMeasure) WHERE username='PLMasterSSB'";

// but actually you replace the "interger" and "TimeMeasure" with the variables $explode3 for "interger" and $explode4 for "TimeMeasure"


MySQL_query("UPDATE register SET banneduntil=DATE_ADD(banneduntil, INTERVAL $explode3 $explode4) WHERE username='PLMasterSSB'";
}
?>



I know I probably didn't explain this good but the part about the substr() and explode() is the part you really need to know.
angelrulez7 (2014-06-01 05:51:47)
Upgrade to mysqli so that all your work isn't ruined if your host updates the PHP version.
a
TheAlexRider (2014-06-18 15:45:13)
What? I never posted. Heh heh heh
 

Log in to submit a comment

This topic's ID: 70589

Back to forum: Web Programming (HTML, JS, CSS, PHP, MySQL)




Total registered users: 8321
New registered users today: 7
Newest registered user: ElegantVulpes

©  Copyright 2026 3DSPlaza. All Rights Reserved