New to Mysql? Read the Series and Become an Expert

New to Mysql? Read the Series and Become an Expert

Fadıl

This is the beginning of a series where I will work through the basic Mysql commands that you will need to manage a database. These commands are covered in this part of the series:

CREATE DATABASE,CREATE TABLE,INSERT,SELECT,FROM,WHERE,AND.

Series name: MissJackson part I, starting out
Skill level: Newbie

So you’ve got Mysql installed and if you are like me you can’t wait to enter all your old baseball cards in your new database so you can sell them on eBay, or maybe you won’t put in your
friend’s/girlfriend’s Birthday, favorite music, address, phone number, favorite music artist…( you don’t ever want to forget your girlfriend’s birthday as you may already know…). Anyway
so you got all this important crap, how do you cram it into Mysql? Ok, first you will have to get into MySQL. Once you are in Mysql you’ve got to create a database so you have something to work
with:

How to Sending E-mail With PHP?

Fadıl

Every web site has email.  Rather it being a feedback form of some sort or a mailto: tag, why make it hard for the visitor to contact you?  When you can take 3 lines of code and create a feedback form the directly sends it to your email from the web browser with the visitor’s input.

Creating a PHP Email form could be the best thing that has ever happened to your site.  So how do you do it? Easy.
You can have any one of your pages send an email when the visitor either visits the page or if the visitor has submitted some sort of input.  When you add the code it needs to be at the top of the page you would like to send from.

Ip Check Using PHP

Fadıl

If you have ever had the need to validate an IP address then this small script is for you.

function validate_ip($ip) {
if (is_string($ip) && ereg('^([0-9]{1,3}).([0-9]{1,3}).' .
'([0-9]{1,3}).([0-9]{1,3})$',
$ip, $part)) {
if ($part[1] <= 255 && $part[2] <= 225 && $parg[3] <= 255 && $part[4] <= 255)
return TRUE; # Valid IP
}
return FALSE; # Invalid IP
}

Ok, that’s all fine and dandy but what does it mean?

The fist if the statement is breaking the IP up into 3 sections and removing the ‘.’ from the user input. It then stores the results in the $part var then the second If statement checks to see if all of the parts are valid. If everything is fine and dandy it will return TRUE and if something has gone wrong it will return FALSE.
Hope this helps anyone.

How to create a random password in PHP

Fadıl

I am trying to generate a random password in PHP.

If you ever have the need to create a random password or username you can use something like this.

function randomPassword($length) { 
  $possible = '0123456789!@#$%^&*()_+' . 
              'abcdefghijklmnopqrstuvwxyz' . 
              'ABCDEFGHIJKLMNOPQRSTUVWXYZ' . 
  $str = ""; 
  while (strlen($str) < $length) { 
     $str .= substr($possible, (rand() % strlen($possible)), 1); 
  } 
  return($str); 
}

How to Database-Driven User Authentication?

Fadıl

Ever have something that you wanted to put on the internet for only a group of
people to see? Well, then this script is for you. All you need is; PHP and MySQL.
Create a MySQL database to store the usernames and passwords.

CREATE TABLE auth_users ( 
  f_name varchar(50) DEFAULT '' NOT NULL, 
  l_name varchar(50) DEFAULT '' NOT NULL, 
  username varchar(50) DEFAULT '' NOT NULL, 
  password varchar(100) DEFAULT '' NOT NULL 
  );

Now that you have a table named auth_users, you can now create an interface to add First names, Last Names, usernames, and passwords.