Skip to content

Instantly share code, notes, and snippets.

@johnmorris
johnmorris / gist:8119109
Last active January 1, 2016 08:38
Force a single (2, 3, 4) column layout in WordPress 3.8
function jmo_screen_layout_columns($columns) {
$columns['dashboard'] = 2;
return $columns;
}
add_filter('screen_layout_columns', 'jmo_screen_layout_columns');
function jmo_screen_layout_dashboard() {
return 2;
@johnmorris
johnmorris / gist:8135167
Created December 26, 2013 15:41
A simple database class using mysqli prepared statements in PHP.
<?php
if ( !class_exists( 'DB' ) ) {
class DB {
public function __construct($user, $password, $database, $host = 'localhost') {
$this->user = $user;
$this->password = $password;
$this->database = $database;
$this->host = $host;
}
protected function connect() {
@johnmorris
johnmorris / gist:8197182
Last active January 1, 2016 20:29
Simple illustration using checkboxes in forms.
<?php
print_r($_POST);
?>
<form method="post">
Car <input type="checkbox" name="stuff[car]" value="1" />
Dog <input type="checkbox" name="stuff[dog]" value="1" />
<input type="submit" value="Submit" />
</form>
@johnmorris
johnmorris / gist:8294982
Last active January 2, 2016 11:09
PHP file upload example
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
print_r($_FILES);
//What folder to save it in
$targetPath = "uploads/";
$allowed_three = array('pdf', 'doc', 'JPG','log', 'txt', 'wpd', 'wps', 'jpg', 'png', 'PEG', 'PNG');
$allowed_four = array('docx');
@johnmorris
johnmorris / gist:9834dc846f1027d568e8
Created December 15, 2014 15:10
Create MySQL tables dynamically using PHP
<?php
// Be sure to input YOUR database details below
// Watch the associated videos here: https://www.youtube.com/playlist?list=PLLs69n7Q4dCx5_7ZwnxTymH8X0iRP_2vw
$db_user = 'DB USERNAME HERE';
$db_pass = 'DB PASSWORD HERE';
$db_name = 'DB NAME HERE';
$db_host = 'localhost';
$mysqli = new mysqli($db_host, $db_user, $db_pass, $db_name);
@johnmorris
johnmorris / gist:6f5d2ad14a7b81096588
Created December 15, 2014 15:18
Connect to a MySQL database with PHP using PDO and MySQLi
<?php
// Be sure to input YOUR database details below
// Watch the associated videos here: https://www.youtube.com/playlist?list=PLLs69n7Q4dCx5_7ZwnxTymH8X0iRP_2vw
$db_user = 'DB USERNAME HERE';
$db_pass = 'DB PASSWORD HERE';
$db_name = 'DB NAME HERE';
$db_host = 'localhost';
//MySQLi
@johnmorris
johnmorris / gist:7a5d6c580b7d50aaf058
Created December 15, 2014 15:22
GET data from a MySQL database with PHP using PDO and MySQLi
<?php
// Be sure to input YOUR database details below
// Watch the associated videos here: https://www.youtube.com/playlist?list=PLLs69n7Q4dCx5_7ZwnxTymH8X0iRP_2vw
$db_user = 'DB USERNAME HERE';
$db_pass = 'DB PASSWORD HERE';
$db_name = 'DB NAME HERE';
$db_host = 'localhost';
// MySQLi
@johnmorris
johnmorris / gist:5bc0b892fe1fbecda4ac
Created December 15, 2014 15:32
INSERT data into a MySQL database with PHP using PDO and MySQLi
<?php
// Be sure to input YOUR database details below
// Watch the associated videos here: https://www.youtube.com/playlist?list=PLLs69n7Q4dCx5_7ZwnxTymH8X0iRP_2vw
$db_user = 'DB USERNAME HERE';
$db_pass = 'DB PASSWORD HERE';
$db_name = 'DB NAME HERE';
$db_host = 'localhost';
$time = time();
@johnmorris
johnmorris / gist:14da47e08fce442dd471
Created December 15, 2014 15:39
UPDATE data in a MySQL database with PHP using PDO and MySQLi
<?php
// Be sure to input YOUR database details below
// Watch the associated videos here: https://www.youtube.com/playlist?list=PLLs69n7Q4dCx5_7ZwnxTymH8X0iRP_2vw
$db_user = 'DB USERNAME HERE';
$db_pass = 'DB PASSWORD HERE';
$db_name = 'DB NAME HERE';
$db_host = 'localhost';
$query = "UPDATE objects
@johnmorris
johnmorris / gist:2a24cab89a5f1f6875ad
Created December 15, 2014 15:45
DELETE data in a MySQL database with PHP using PDO and MySQLi
<?php
// Be sure to input YOUR database details below
// Watch the associated videos here: https://www.youtube.com/playlist?list=PLLs69n7Q4dCx5_7ZwnxTymH8X0iRP_2vw
$db_user = 'DB USERNAME HERE';
$db_pass = 'DB PASSWORD HERE';
$db_name = 'DB NAME HERE';
$db_host = 'localhost';
$query = "DELETE FROM objects