(207) 337-0313
The Web Agent's Blog The Web Agent's Facebook The Web Agent's LinkedIn The Web Agent's X The Web Agent's Instagram The Web Agent's YouTube Channel

Code Samples

Cheat sheet with basic code snippets so that I can easily copy/paste them quickly. Feel free to use them too if you find it helpful.

I code on the LAMP stack, so you'll mostly find PHP, JavaScript, HTML, and CSS code samples on my site. I'll add to this page as I encounter more bits of code I use a lot that I want to put on here for easy access.

Or, maybe you're here because you just need pro help with some code...

Call or text me at (207) 337-0313.

(Yes, I actually pick up the phone.)

Commonly Used Code Samples to Copy/Paste


<?php if( ){ ?>

<?php } ?>

<?php if( isset($var) && $var != "" ){ ?>

<?php } ?>


} while ($row_var = mysqli_fetch_assoc($var));

$query_var = sprintf("SQL HERE");
$var = $mysqli->query($query_var);
$row_var = mysqli_fetch_assoc($var);
$totalRows_var = $var->num_rows;

ini_set("display_errors", 1);

function functionName(){


function switchThis($i) {
switch ($i) {
case "option_1":
echo "1";
case "option_2":
echo "2";

$numbers = array("one", "two", "three");

foreach ($numbers as $value) {
echo "$value <br />";

$hostname_data = "enter_hostname";
$database_data = "enter_database_name";
$username_data = "enter_username";
$password_data = "enter_password";

$mysqli = new mysqli($hostname_data, $username_data, $password_data, $database_data);


JavaScript & jQuery



$('#buttonName').on('click', function(){


function functionName($var){
var a = $var;

function fieldClassValidate(){
if( $('.fieldClass').is(':checked') ){
//do something
//do nothing

function functionName($var){

var id = $var;
var dataString = "id=" + id;

type: "POST",
url: "pageName.php",
data: dataString,
cache: false,
beforeSend: function(){
var answer = confirm("Are you sure?");
if (answer){
return true;
} else {
return false;
success: function(){
alert("Processed " + id);


document.getElementById("submit").disabled = true;
var a = document.getElementById("fieldID").value;

$('.className').on('change', function(){
$(this).val($(this).val().replace(/\s+/g, ''));

$('elementID').addClass( "className" );


<!DOCTYPE html>
<html lang="en-US">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Enter Title</title>
<meta name="description" content="Enter description.">
<link rel="canonical" href="" />
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="theme-color" content="#ffffff">

<div class="container">
<div class="row">
<div class="col-12 col-md-6">
<div class="col-12 col-md-6">


@import url('//fonts.googleapis.com/css?family=fontName');

@media (max-width: 1200px) {

What's next?

Call or text Del at (207) 337-0313 to discuss your needs. No pressure. No obligation.