Skip to content

Instantly share code, notes, and snippets.

@johnmorris
johnmorris / index.php
Created July 31, 2015 03:03
Submit a form, post the data and format the response using jQuery and AJAX (full tutorial here: http://youtu.be/-nkud6TwXBI)
<!DOCTYPE html>
<html>
<head>
<title>Get Data From a MySQL Database Using jQuery and PHP</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
// Set form variable
var form = $('#search_form');
@johnmorris
johnmorris / about.php
Last active September 19, 2019 13:30
Load content into a div on click using jQuery and AJAX (video tutorial here: http://youtu.be/ae-FqAt_VCA)
<h1>About</h1>
<p>This is the about page</p>
@johnmorris
johnmorris / johnmorris-grid.php
Created July 16, 2015 03:05
Build a grid layout for WordPress using WP_Query (video tutorial: https://youtu.be/MF0egfd5LwU)
<?php
/*
Plugin Name: John Morris Grid
Plugin URI: http://johnmorrisonline.com/
Description: Demo plugin that displays posts in a grid format via shortcode
Version: 1.0.1
Author: John Morris
Author URI: http://johnmorrisonline.com
Text Domain: johnmorris-grid
License: GNU General Public License v2 or later
@johnmorris
johnmorris / navigation.php
Created July 10, 2015 16:05
A pure HTML and CSS dropdown menu (tutorial: http://youtu.be/uwUqsILfWoI)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Pure CSS Dropdown Navigation</title>
<style>
body, html {
margin: 0;
font-family: Arial, sans-serif;
font-size: 1em;
@johnmorris
johnmorris / escape.php
Created June 18, 2015 13:22
Prevent XSS attacks using htmlspecialchars and htmlentities. Full video tutorial here: http://youtu.be/pc0V9hJpE54
<?php
function _e($string) {
echo htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
//echo htmlentities($string, ENT_QUOTES, 'UTF-8');
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
@johnmorris
johnmorris / class-hash-password.php
Created May 12, 2015 17:40
How to hash and store passwords in PHP
<?php
/**
* Performs password hashing
*
* This class is used to perform common password hashing routines
*
* @version 1.0
* @author John Morris <[email protected]>
*/
class Hash_Password {
@johnmorris
johnmorris / class-validate-email.php
Created April 28, 2015 18:08
How validate an email address in PHP (by domain)
<?php
/**
* Validates email addresses
*
* This class is used to validate email addresses using several different criteria.
*
* @version 1.0
* @author John Morris <[email protected]>
*/
class validate_email {
@johnmorris
johnmorris / gist:17919f785e2caff296ed
Created December 15, 2014 16:01
Using ezSQL in PHP and MySQL projects
<?php
// Be sure to configure your file paths according to YOUR setup below
// Watch the associated videos here: https://www.youtube.com/playlist?list=PLLs69n7Q4dCx5_7ZwnxTymH8X0iRP_2vw
require_once( dirname( __FILE__ ) . '/config.php' );
require_once( dirname( __FILE__ ) . '/shared/ez_sql_core.php' );
require_once( dirname( __FILE__ ) . '/mysqli/ez_sql_mysqli.php' );
$db = new ezSQL_mysqli(DB_USER, DB_PASS, DB_NAME, DB_HOST, DB_ENCODING);
@johnmorris
johnmorris / gist:6001ad2b4ef82d114b77
Created December 15, 2014 15:57
Database class for prepared statements in PHP using MySQLi
<?php
// Be sure to input YOUR database details below
// Watch the associated videos here: https://www.youtube.com/playlist?list=PLLs69n7Q4dCx5_7ZwnxTymH8X0iRP_2vw
define( 'DB_USER', 'DB USERNAME' );
define( 'DB_PASS', 'DB PASSWORD' );
define( 'DB_NAME', 'DB NAME' );
define( 'DB_HOST', 'localhost' );
define( 'DB_ENCODING', '' );
@johnmorris
johnmorris / gist:77bf141302ae147d6ee8
Created December 15, 2014 15:51
Query a MySQL database using prepared statements in PHP for 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