Thursday, May 10, 2012

Project #1 - Simple Guestbook

PHP Project #1 - Simple Guestbook
Goal: Create an online guestbook where people can put in their name and comment.  It will then be put into a database.  Then below the form, it will display all the comments in the guestbook with the newest one on top.

Things to work on:  The PHP does not sanitize. 
Code

Tuesday, May 1, 2012

MYSQL commands

A list of commands used in MYSQL.  The more commands I learn, the more I'll add to the list.

Create a database
CREATE DATABASE [databasename];
Show all tables in database
show tables ;
To make a database your active database
USE [databasename];
Create a table
CREATE TABLE [tablename] ( [col(1)title] [type] , [col(2)title] [type] ,...,[col(n)title] [type]) ; 
Insert data in to table
INSERT INTO [tablename] ( [col(1)title], [col(2)title],..., [col(n)title] ) VALUES ( [dataforcol(1)], [dataforcol(2)],..., [dataforcol(n)],);
Shows the structure of the table
DESCRIBE [tablename];
Show all data in table
SELECT * FROM [tablename];

Show specific data (x)  in table
SELECT * FROM [tablename] WHERE [col_title] = "[x]";


Add a column (in front)
ALTER TABLE [tablename] ADD  [col_title] [type] FIRST;
Add a column (anywhere after col(N) )
ALTER TABLE [tablename] ADD [col_title] [type] AFTER [col(N)title];
Delete a column
ALTER TABLE [tablename] DROP [col_title];
Change column type
ALTER TABLE [tablename] MODIFY [col_title] [type];
Change column name (and type)
ALTER TABLE [tablename] CHANGE  [old_col_title] [new_col_title] [type];
Delete data entry/row
DELETE from [tablename] WHERE [col_title] = '[element]';
Delete all data in table
DELETE from [tablename];