Learning PHP and MySQL
Categories
Blogging
News
Personal
Chapter 3 Code
- Example 03-01 All you need to start with PHP is a simple HTML document
- Example 03-02 Adding PHP Code to an HTML File
- Example 03-03 Calling echo() and print()
- Example 03-04 The HTML markup produced by the PHP code
- Example 03-05 Using comments to make your code easier to read
- Example 03-06 Reassigning a variable
- Example 03-07 The default handling of variable scope
- Example 03-08 Using a global variable changes the result
- Example 03-09 A static variable remembering its last value
- Example 03-10 PHP_SELF being used with a file called test.php
- Example 03-11 Working with strings
- Example 03-12 Using a variable in a string definition
- Example 03-13 Single quotes used in a string assignment
- Example 03-14 Various special characters in string assignments
- Example 03-15 Using echo with special characters
- Example 03-16 Correct escaping of special characters
- Example 03-17 Using strcmp to compare two stings
- Example 03-18 Concatenating strings together
- Example 03-19 Combining a string and a number
- Example 03-20 Using a constant in your program
- Example 03-22 PHP mathematical function usage
- Example 03-23 Using autoincrement to add to a variable
- Example 03-24 Using the autodecrement operator
- Example 03-25 Using pre- and post-increment
- Example 3-21 Echoing the line and file predefined constants for a script called predefined_constants
Chapter 4 Code
- Example 04-01 Sum of values
- Example 04-02 Casting a variable
- Example 04-03 Lefthand expressions
- Example 04-04 Order of precedence
- Example 04-05 The multiplication is done last because of the override
- Example 04-06 Else and if statements
- Example 04-07 Checking multiple conditions
- Example 04-08 Using the ? operator to create a message
- Example 04-09 Using if to test for multiple values
- Example 04-10 Using switch to test for multiple values
- Example 04-11 What happens when there are no break keywords
- Example 04-12 Using the DEFAULT: statement to generate an error
- Example 04-13 Using endswitch to end the switch definition
- Example 04-14 A sample while loop that counts to 10
- Example 04-15 Counting to 10 with do… while
- Example 04-16 Using break to avoid division by zero
- Example 04-17 Using continue instead of break
Chapter 5 Code
- Example 05-01 The ubiquitous Hello world!
- Example 05-02 Displaying information about the PHP environment
- Example 05-03 Creating an md5 signature
- Example 05-04 Using the string capitalization functions
- Example 05-05 Creating a capitalize function with a default parameter $each
- Example 05-06 Modifying capitalize to take a reference parameter
- Example 05-07 A sample include file called add.php
- Example 05-08 Using the include function
- Example 05-09 Using include_once to include a file
- Example 05-10 Creating an object from the Cat class
- Example 05-11 Creating the Cat constructor
- Example 05-12 Using the PHP 5 style constructor
- Example 05-13 Defining three member functions for Cat
- Example 05-14 Creating a new object without saving the reference
- Example 05-15 Adding the $age variable to Cat
- Example 05-16 Accessing the $age variable using this-->
- Example 05-17 Using the extends keyword to define a subclass
- Example 05-18 Using the parent construct
- Example 05-19 Calling the constructor of the parent class
- Example 05-20 Using the -> operator to call hypnotize
- Example 05-21 Referencing the $some_variable
- Question 05-01 What’s wrong with this function call?
Chapter 6 Code
- Example 06-01 Using the array function to create an array of weekdays
- Example 06-02 Creating an associative array of shapes
- Example 06-03 Displaying one value from an array
- Example 06-04 Display the contents of an array using a loop
- Example 06-05 Counting the elements in an array
- Example 06-06 Using sort to alphabetize
- Example 06-07 Creating a multidimensional array
- Example 06-08 Displaying a multidimensional array
- Example 06-09 Using extract on an associative array
- Example 06-10 Using extract with the EXTR_PREFIX_ALL directive
- Example 06-11 Using EXTR_PREFIX_ALL on a numeric array
Chapter 7 Code
Chapter 8 Code
- Example 08-01 The contents of the my_backup.sql file
- Example 08-02 Book titles in CSV format
- Example 08-03 Creating a simple index
- Example 08-04 Using CONCAT to put fields together
- Example 08-05 Calculating the length of a string
- Example 08-06 Changing the case of the title
- Example 08-07 Using the LEADING option to remove zeros
- Example 08-08 Using TRIM with the TRAILING option
- Example 08-09 Looking for the string in our author names
- Example 08-10 Adding the formatting to a phone number using LEFT, RIGHT, and SUBSTR
- Example 08-11 Using WEEKDAY to get the day of the week
- Example 08-12 Using DAYNAME to get the day of the week as a name
- Example 08-13 Finding days since the start of the year
- Example 08-14 Using MONTH and MONTHNAME on the purchases table
- Example 08-15 Using HOUR and MINUTE on a time
- Example 08-16 Using DATE_SUB to subtract days
- Example 08-17 Using the minus operator on a date
- Example 08-18 Using DATE_FORMAT with a string to place colons between the segments
Chapter 9 Code
- Example 09-01 PHP file format
- Example 09-02 The db_login.php file with values filled in2
- Example 09-03 The SQL to recreate the test objects8
- Example 09-04 Including the connection values and calling mysql_connect
- Example 09-05 Displaying the books and authors
- Example 09-06 Displaying the results of a query in an HTML table
- Example 09-07 Displaying the books table with PEAR DB
Chapter 10 Code
- Creating myapp/index.php
- Example 10-01 A simple form example
- Example 10-02 Modifying our simple search to process the results
- Example 10-03 Form default values
- Example 10-04 Multiple book types
- Example 10-05 A form with checkboxes using the same name to store multiple values
- Example 10-06 Checking input from a radio button or a single select
- Example 10-07 Checking input from a checkbox or a multiple select
- Example 10-08 PHP feet-to-meters converter
- Example 10-09 Converting between time zones based on user input
- Example 10-10 Combining form processing and database querying
- Example 10-11 The index.php file to create
- Example 10-12 The sample index.tpl template to create
- Example 10-13 Using the template to display the table
- Example 10-14 The new table template
- Figure 10-03 Text boxes
- Figure 10-04 A simple form with a text area element
- Figure 10-05 Checkboxes
- Figure 10-06 Radio buttons
- Figure 10-09 Selecting Italian and Chinese
Chapter 11 Code
- Example 11-01 Displaying a number in binary format
- Example 11-02 printf puts the numbers into the string
- Example 11-03 Displaying the same number in different formats
- Example 11-04 Using left zero padding
- Example 11-05 Using left space padding
- Example 11-06 Adding the and tags so the spaces display
- Example 11-07 Left padding using the default of spaces
- Example 11-08 Right padding with spaces
- Example 11-09 Displaying a real number in money format
- Example 11-11 Calculating the length of a string
- Example 11-12 Using the word case functions
- Example 11-13 Detecting whether a string is contained in another string
- Example 11-14 Using several functions together to extract a portion of a string
- Example 11-15 A simple echo of the timestamp
- Example 11-16 Making the date and time appear like we expect
- Example 11-17 Adding two days to the date
- Example 11-18 Validating two dates
- Example 11-19 Creating a timestamp from the components of a date
- Example 11-20 The file_exists.php script checks to see if the file is there
- Example 11-21 Checking the permissions of a file
- Example 11-22 Using file_exists, touch, and unlink together
- Example 11-23 Renaming a file
- Example 11-24 Prompting to upload a file
- Example 11-25 Checking for the existence of an uploaded file
- Example 11-26 Checking the file size
- Example 11-27 Checking the file type
- Example 11-28 Processing an uploaded file
- Example 11-29 Executing df and displaying the results
Chapter 12 Code
- Cross-Site Scripting Attacks
- Example 12-1 Creating a table from a PHP page in create_table.php
- Example 12-10 The delete.php code for performing a delete
- Example 12-11 Using mysql_insert_id to link up an author to a title
- Example 12-12 Displaying the authors in a list
- Example 12-2 Dropping the purchases table in drop.php
- Example 12-3 Using a predefined INSERT statement in insert.php
- Example 12-4 Using embedded links to provide a purchase button in pear_purchase_example.php
- Example 12-5 The file purchase.php processes the user action based on the title_id parameter
- Example 12-6 Using input from a form to add a title
- Example 12-7 Checking for magic quotes
- Example 12-8 Updating a field
- Example 12-9 Providing a link to delete a purchase in deletion_link.php
- SQL Injection
Chapter 13 Code
- Example 13-1 Creating a cookie
- Example 13-10 Simply starting a session
- Example 13-11 Registering a variable with session_register
- Example 13-12 Registering a variable by including it in $_SESSION
- Example 13-13 Referencing a variable set on a prior page in the session
- Example 13-14 Checking to see whether a user is valid
- Example 13-15 Destroying a session
- Example 13-16 Session timeout
- Example 13-17 pear install Auth output
- Example 13-18 pear install Auth_HTTP output
- Example 13-19 Using Auth_HTTP to authenticate a user
- Example 13-2 Viewing the username cookie
- Example 13-20 Retrieving additional information for the user
- Example 13-3 Destroying a cookie by expiring it in the recent past
- Example 13-4 Using HTTP authentication with a PHP script
- Example 13-5 Checking the values returned from the authentication prompt
- Example 13-6 Creating the users table to store login information
- Example 13-7 Creating the entry in the database for a user with an encrypted password
- Example 13-8 The database login details
- Example 13-9 Verifying a username and password against the database
Chapter 14 Code
- Example 14-1 Using Apache authentication to restrict access to scripts
- Example 14-10 Suppressing the standard database error message
- Example 14-11 Seeing the results of magic quotes
- Example 14-12 Checking for magic quotes
- Example 14-2 Creating an Apache password for .htaccess
- Example 14-3 Comparing the output of md5 to that of sha1
- Example 14-4 Not initializing a variable was a hole in sample.php
- Example 14-5 Sessions with register_globals on or off in session_test.php
- Example 14-6 Session using the proper $_SESSION super global
- Example 14-7 Detecting simple variable poisoning
- Example 14-8 Checking for session hijacking
- Example 14-9 session.save_path functionality
Chapter 15 Code
- Example 15-1 Building a form that validates its fields before submission
- Example 15-2 The file source.js contains functions to check the various fields
- Example 15-3 Using preg_match to return an array of matches that start with ple
- Example 15-4 Displaying an error from PHP and redisplaying the form with submitted values
Chapter 16 Code
- Example 16-1 The config.php script defines settings that are used throughout the site
- Example 16-10 The posts.php script displays a listing of posts and their subjects
- Example 16-11 The posts.tpl template file defines how the postings appear on the page
- Example 16-12 The view_post.php script displays and a summary of its comments
- Example 16-13 view_post.tpl
- Example 16-14 modify_posts.php
- Example 16-15 post_form.tpl
- Example 16-16 modify_comment.php
- Example 16-17 comment_form.tpl
- Example 16-2 The header.tpl file
- Example 16-3 The footer.tpl file
- Example 16-4 The login script, called login.php
- Example 16-5 SQL to create the posts table
- Example 16-6 SQL to create the categories table
- Example 16-7 SQL to create the comments table
- Example 16-8 SQL to create the users table (may have already been created
- Example 16-9 Inserting sample data for the tables
Chapter 17 Code