Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Server Development
Habbo Retros
Habbo Q&A
Mysql Query Problem
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="GarettM" data-source="post: 308988" data-attributes="member: 839"><p>Here is what i did to make this work.</p><p></p><p>Created a table called JayCustom.groups;</p><p>[CODE]</p><p>CREATE DATABASE JayCustom;</p><p></p><p>CREATE TABLE JayCustom.groups</p><p>(</p><p> `id` INT NOT NULL AUTO_INCREMENT,</p><p> `name` TINYTEXT DEFAULT NULL,</p><p> `desc` MEDIUMTEXT DEFAULT NULL,</p><p> `badge` TINYTEXT DEFAULT NULL,</p><p> `ownerid` MEDIUMINT NOT NULL,</p><p> `created` DATETIME DEFAULT CURRENT_TIMESTAMP,</p><p> `roomid` INT DEFAULT NULL,</p><p> `locked` ENUM('open', 'closed', 'locked') DEFAULT 'open',</p><p> `privacy` ENUM('open', 'blocked') DEFAULT 'open',</p><p> PRIMARY KEY (id)</p><p>) Engine=InnoDB;</p><p>[/CODE]</p><p>used mysqli query and ran this query.</p><p>[CODE]INSERT INTO groups (`name`, `desc`, `badge`, `ownerid`, `created`, `roomid`, `locked`, `privacy`) VALUES ('Staff', 'Official Staff Group!', 'staff', '1', '2014-10-20 07:09:29', '1', 'open', 'open');[/CODE]</p><p>Here are the variables i used.</p><p>[PHP]</p><p> # Variables</p><p> $name = 'Staff';</p><p> $description = 'Official Staff Group!';</p><p> $badge = 'staff'; // sorry don't know the staff badge code.</p><p> $owner = 1; // USER_ID</p><p> // Date must be formated YYYY-MM-DD HH:MM:SS</p><p> $created = date('Y-m-d h:i:s', time()); // should be 2014-10-20 10:59:23 - My local Time. Location: Gresham, OR, United States of America.</p><p> $room = 1;</p><p> $locked = 'open';</p><p> $privacy = 'open';</p><p></p><p> # Run Query</p><p> $query = dbquery(</p><p> sprintf(</p><p> "INSERT INTO `groups` (`name`, `desc`, `badge`, `ownerid`, `created`, `roomid`, `locked`, `privacy`) VALUES ('%s', '%s', '%s', '%d', '%s', '%d', '%s', '%s');",</p><p> $name,</p><p> $description,</p><p> $badge,</p><p> $owner,</p><p> $created,</p><p> $room,</p><p> $locked,</p><p> $privacy</p><p> )</p><p> );</p><p></p><p> if($query == true) {</p><p> echo 'The Group was created successfully <br />';</p><p> } else {</p><p> echo 'The Group was not created successfully <br />';</p><p> }</p><p>[/PHP]</p><p>Here is the full script,</p><p>[PHP]</p><p><?php</p><p> # Time zone</p><p> date_default_timezone_set('UTC');</p><p></p><p> # Simple Database Query</p><p> $database = new mysqli('localhost', 'root', 'devbest', 'JayCustom'); // i don't care if my development servers password is on devbest</p><p></p><p> if($database->connect_errno) {</p><p> echo sprintf('Script Error: The database could not connect because "%s"', $database-connect_error);</p><p> exit;</p><p> }</p><p></p><p> function dbquery($query) {</p><p> global $database;</p><p></p><p> if($result = $database->query($query)) {</p><p> return true;</p><p> }</p><p> return false;</p><p> }</p><p></p><p> # Variables</p><p> $name = 'Staff';</p><p> $description = 'Official Staff Group!';</p><p> $badge = 'staff'; // sorry don't know the staff badge code.</p><p> $owner = 1; // USER_ID</p><p> // Date must be formated YYYY-MM-DD HH:MM:SS</p><p> $created = date('Y-m-d h:i:s', time()); // should be 2014-10-20 10:59:23 - My local Time. Location: Gresham, OR, United States of America.</p><p> $room = 1;</p><p> $locked = 'open';</p><p> $privacy = 'open';</p><p></p><p> # Run Query</p><p> $query = dbquery(</p><p> sprintf(</p><p> "INSERT INTO `groups` (`name`, `desc`, `badge`, `ownerid`, `created`, `roomid`, `locked`, `privacy`) VALUES ('%s', '%s', '%s', '%d', '%s', '%d', '%s', '%s');",</p><p> $name,</p><p> $description,</p><p> $badge,</p><p> $owner,</p><p> $created,</p><p> $room,</p><p> $locked,</p><p> $privacy</p><p> )</p><p> );</p><p></p><p># Results</p><p> if($query == true) {</p><p> echo 'The Group was created successfully <br />';</p><p> } else {</p><p> echo 'The Group was not created successfully <br />';</p><p> }</p><p>[/PHP]</p><p></p><p></p><p>IMPORTANT NOTE!!!</p><p>Programmers don't recommend using $_POST, $_GET or $_SERVER variables directly</p><p>[PHP]</p><p><?php</p><p># standards don't recommend using $_POST, $_$SERVER or $_GET directly.</p><p> $rid = (int) filter_input(INPUT_POST, 'room_id');</p><p> $name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_SPECIAL_CHARS);</p><p> $desc = filter_input(INPUT_POST, 'desc', FILTER_SANITIZE_SPECIAL_CHARS);</p><p> $priv = filter_input(INPUT_POST, 'priv', FILTER_SANITIZE_SPECIAL_CHARS);</p><p> $stat = filter_input(INPUT_POST, 'stat', FILTER_SANITIZE_SPECIAL_CHARS);</p><p> $badge = filter_input(INPUT_POST, 'img', FILTER_SANITIZE_SPECIAL_CHARS);</p><p> $date = date('Y-m-d h:i:s', time());</p><p>[/PHP]</p></blockquote><p></p>
[QUOTE="GarettM, post: 308988, member: 839"] Here is what i did to make this work. Created a table called JayCustom.groups; [CODE] CREATE DATABASE JayCustom; CREATE TABLE JayCustom.groups ( `id` INT NOT NULL AUTO_INCREMENT, `name` TINYTEXT DEFAULT NULL, `desc` MEDIUMTEXT DEFAULT NULL, `badge` TINYTEXT DEFAULT NULL, `ownerid` MEDIUMINT NOT NULL, `created` DATETIME DEFAULT CURRENT_TIMESTAMP, `roomid` INT DEFAULT NULL, `locked` ENUM('open', 'closed', 'locked') DEFAULT 'open', `privacy` ENUM('open', 'blocked') DEFAULT 'open', PRIMARY KEY (id) ) Engine=InnoDB; [/CODE] used mysqli query and ran this query. [CODE]INSERT INTO groups (`name`, `desc`, `badge`, `ownerid`, `created`, `roomid`, `locked`, `privacy`) VALUES ('Staff', 'Official Staff Group!', 'staff', '1', '2014-10-20 07:09:29', '1', 'open', 'open');[/CODE] Here are the variables i used. [PHP] # Variables $name = 'Staff'; $description = 'Official Staff Group!'; $badge = 'staff'; // sorry don't know the staff badge code. $owner = 1; // USER_ID // Date must be formated YYYY-MM-DD HH:MM:SS $created = date('Y-m-d h:i:s', time()); // should be 2014-10-20 10:59:23 - My local Time. Location: Gresham, OR, United States of America. $room = 1; $locked = 'open'; $privacy = 'open'; # Run Query $query = dbquery( sprintf( "INSERT INTO `groups` (`name`, `desc`, `badge`, `ownerid`, `created`, `roomid`, `locked`, `privacy`) VALUES ('%s', '%s', '%s', '%d', '%s', '%d', '%s', '%s');", $name, $description, $badge, $owner, $created, $room, $locked, $privacy ) ); if($query == true) { echo 'The Group was created successfully <br />'; } else { echo 'The Group was not created successfully <br />'; } [/PHP] Here is the full script, [PHP] <?php # Time zone date_default_timezone_set('UTC'); # Simple Database Query $database = new mysqli('localhost', 'root', 'devbest', 'JayCustom'); // i don't care if my development servers password is on devbest if($database->connect_errno) { echo sprintf('Script Error: The database could not connect because "%s"', $database-connect_error); exit; } function dbquery($query) { global $database; if($result = $database->query($query)) { return true; } return false; } # Variables $name = 'Staff'; $description = 'Official Staff Group!'; $badge = 'staff'; // sorry don't know the staff badge code. $owner = 1; // USER_ID // Date must be formated YYYY-MM-DD HH:MM:SS $created = date('Y-m-d h:i:s', time()); // should be 2014-10-20 10:59:23 - My local Time. Location: Gresham, OR, United States of America. $room = 1; $locked = 'open'; $privacy = 'open'; # Run Query $query = dbquery( sprintf( "INSERT INTO `groups` (`name`, `desc`, `badge`, `ownerid`, `created`, `roomid`, `locked`, `privacy`) VALUES ('%s', '%s', '%s', '%d', '%s', '%d', '%s', '%s');", $name, $description, $badge, $owner, $created, $room, $locked, $privacy ) ); # Results if($query == true) { echo 'The Group was created successfully <br />'; } else { echo 'The Group was not created successfully <br />'; } [/PHP] IMPORTANT NOTE!!! Programmers don't recommend using $_POST, $_GET or $_SERVER variables directly [PHP] <?php # standards don't recommend using $_POST, $_$SERVER or $_GET directly. $rid = (int) filter_input(INPUT_POST, 'room_id'); $name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_SPECIAL_CHARS); $desc = filter_input(INPUT_POST, 'desc', FILTER_SANITIZE_SPECIAL_CHARS); $priv = filter_input(INPUT_POST, 'priv', FILTER_SANITIZE_SPECIAL_CHARS); $stat = filter_input(INPUT_POST, 'stat', FILTER_SANITIZE_SPECIAL_CHARS); $badge = filter_input(INPUT_POST, 'img', FILTER_SANITIZE_SPECIAL_CHARS); $date = date('Y-m-d h:i:s', time()); [/PHP] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Server Development
Habbo Retros
Habbo Q&A
Mysql Query Problem
Top