PHP+Markup

=PHP Markup=

PHP Tutorials
http://phpforms.net/tutorial/tutorial.html

PHP Documentation
[]

Download Documentation
[]

Note: Make sure php files have the .php extension or the scripts will not run.

Start PHP/End PHP
code  code

PHP Short Tags - Considered Bad Form
code <?   ?> <?=   ?> code

These can be enabled on the web server but if you deliver files to a server with these turned off, your scripting won't work.

You may find these in tutorials or older php files. Make sure to change this markup when updating legacy files.

ASP Short Tags - Considered Very Bad Form
code <%   %> <%=   %> code

These can be enabled on the web server but if you deliver files to a server with these turned off, your scripting won't work.

You may find these in tutorials or older php files. Make sure to change this markup when updating legacy files.

Calling the phpinfo Function
code  code

FYI: if you leave this file on your live server, people could find it and learn information about your setup that you would not want them to know. For security reasons, you will want to remove this from the live server directory.

Alert Function
This script is just entered in the php. echo " alert($myVariable) ";

=Connecting to a MySQL Database= From PHP Essentials Training - Kevin Skoglund

Database Constants (Include)
code  code

Connecting to the Database (Include)
code  code

Example of Query Functions (Include)
code <?php // This file is the place to store all basic functions

function confirm_query($result_set) { if (!$result_set) { die("Database query failed: " . mysql_error); }   }

function get_all_subjects { global $connection; $query = "SELECT *               FROM subjects                ORDER BY position ASC"; $subject_set = mysql_query($query, $connection); confirm_query($subject_set); return $subject_set; }

function get_pages_for_subject($subject_id) { global $connection; $query = "SELECT *               FROM pages                WHERE subject_id = {$subject_id}                ORDER BY position ASC"; $page_set = mysql_query($query, $connection); confirm_query($page_set); return $page_set; }

?> code

Close Connection (Footer Include)

code Copyright 2010, Org Name  code

Content.php

code     

code

=Encoding HTML and URLs=

code character$'; $link_text = " & you'll see";

$url = 'http://localhost/"; $url .= rawurlencode($url_page); $url .= "?param1=" . urlencode($param1); $url .= "&param2=" . urlencode($param2);

?>

">   code

=Overarching Escape Function for Preparing MySQL Values=

code <?php function mysql_prep($value) { $magic_quotes_active = get_magic_quotes_gpc; $new_enough_php_version = function_exists("mysql_real_escape_string"); // i.e. PHP v4.3.0 or greater

if($new_enough_php_version) { // undo magic quote effects and use mysql_real_escape_string if($magic_quotes_active) { $value = stripslashes($value); } $value = mysql_real_escape_string($value); } else { // before PHP v4.3.0 // if magic quotes are not on, add slashes if(!$magic_quotes_active) { $value = addslashes($value); } // do not need else - if magic quotes active, then have slashes already }       return $value; // this value is clean!!! } ?> code

.