Great Post! Just a couple additions that I've seen asked MANY times.
If you ever have a problem with MySQL. Eg: Won't insert or update, nothing happens, etc. Here is the two best ways I have found to error check any MySQL problem.
Create two variables, one that holds the statement you want to execute, and a seperate one to actualy execute it using mysql_query()
$string = "INSERT INTO table (first, last, email) VALUES('$first', '$last', '$email')";
$query = mysql_query($string);
Now, to do the error checking, print out the string to be executed so you can see what MySQL is ACTUALLY executing. Then, use mysql_error() along with mysql_query() for error checking.
$string = "INSERT INTO table (first, last, email) VALUES('$first', '$last', '$email')";
print $string . "<br>";
$query = mysql_query($string) or die(mysql_error());
That should help you solve any MySQL problem. Also, watch the use of reserved words. Make sure you're not using datatypes or built-in MySQL functions for column names.
Inserting current time/date into MySQL
NOW()
That is MySQL's built in function for inserting the current date/time. Create a date or timestamp field for example, then to insert the current date/time, use
$query = mysql_query("INSERT INTO table (inputed_time) VALUES(NOW())") or die(mysql_error());
Notice how I didn't create two seperate variables. If I did it like this:
// This is the wrong way
$string = "INSERT INTO table (inputed_time) VALUES(NOW())";
$query = mysql_query($string) or die(mysql_error());
It wouldn't work. NOW() is not a PHP function; it needs to be executed as a mysql function, thus, the first way is the correct way to do it.
How to retrieve and display data from database
Once you have your table setup and information is stored in it, all you do to put the information on the browser is query the database then display it.
SELECT
Here's an example:
// replace these with your credentials
$server = "localhost";
$user = "cgraz";
$password = "phpb";
$database = "contacts";
// Connect to Server
mysql_connect($server, $user, $pass) or die(mysql_error());
// Select Database
mysql_select_db($database) or die(mysql_error());
// Query the Database
$query = mysql_query("SELECT * FROM table"); // replace table with your table name
while($row = mysql_fetch_array($query)) { // put results into an array
echo "Name: " . $row["name"] . "<br>"; // (assuming field name in db is 'name'
echo "Email: " . $row["email"] . "<br>"; // (assuming field name in db is email)
// and so forth
// close the while loop
}
And that's it!
Cgraz