Dec
6
2011

Mysql Database with PHP and HTML with search function Part 2

Mysql and PHP

Setting up your database is relatively simple; keeping your login details close to hand, login to 000webhost.com. After setting up your host name (mine is bencraven.comyr.com) enter your Cpanel, and click MySql.

MYSQL and PHP

Under ‘create new database and user’, set the database name to ‘test’ (lower case) and the user name to ‘test’ (also lower case), remember your password.

Note: The service will provide you with a combination of characters prior to your user name and database name, this is fine, it will look something like ‘a6949157_test’ when you’re done.

Remember the following information when you’re finished! Note it down, you will use it in a couple of pages. It will look something like the following:

$mysql_host = “mysql6.000webhost.com”;
$mysql_database = “a6949157_test”;
$mysql_user = “a6949157_test”;
$mysql_password = “yourpassword”;

You’ve created a database! Next step is to set up a table. Go to your MySql page to manage your databases, you want to ‘enter phpmyadmin’, which is a hyperlink located in the paragraph of text above your database name. Click ‘Enter Phpmyadmin’ again on the next page. There are other options to phpmyadmin, but it is certainly one of the most commonly used, and comes with 000webhost, so… that’s good news.

PHPMYADMIN

For your table settings, choose Name: table1, and for number of fields choose 4. Then select ‘go’ and your first table will be created.

  • Your details can all be different to the ones I’ve chosen, just remember what you choose, and relate back to earlier stages if you’re having problems with connecting.
  • You don’t have to use the same number of fields either, just remember to include them in your form later.

Mysql Database Table

Now, I won’t go through the differences between settings like Varchar now, there are a lot of them, I will write up a reference another time.

Set your first field name to ‘id’, your second to ‘fname’ third to ‘lname’ and fourth to ‘phone’. This should demonstrate 3 types of field. The id field will always be unique, so select ‘primary key’ of the selectable round icons on the right of the row, and set it’s ‘extra’ to ‘auto_increment’. You also want to change the ‘Type’ to ‘TINYINT’, which means tiny integer, referring to just numbers. Auto increment means when a new field is added, it lists it in ascending order by number, keeping it unique.

Set the following types for the remaining fields:

  • fname – MEDTEXT
  • lname – MEDTEXT
  • phone – SMALLINT

PHP AND MYSQL

Click ‘Save’ below, and your table is ready! :) You should be redirected to something that looks like this:

PHP AND MYSQL

 

When you’re ready, move on to page 3! Or, return to the previous page.

Leave a comment