Before storing the php form data in MySql it is essential to establish connection with PhpMyAdmin and MySql database. Php has an inbuilt function 'mysql_connect( )', which is used to make connection with PhpMyAdmin and the function 'mysql_select_db( )', is used to make the connection with database.
SYNTAX OF USING MYSQL_SELECT( ) AND MYSQL_SELECT_DB( )
@mysql_select('host name', 'username', 'password');
@mysql_select_db('database name');
mysql_connect( ) function takes three parameters. First parameter is host name, Second parameter is username and the third parameter is password.
Mysql_select_db( ) function take only one parameter that is database name.
@ sign is used to hide the warning message. If you don't use @ sing error message will appear in browser if any error occurred in the connection with PhpMyAdmin and database. To hide this warning message @ sign is used before the statement.
Die() statement is used to show the user defined error message when any error occurred in the connection with PhpMyAdmin or with database. it is advisable not to use die() statement when you are working on live project because no one wants to show any error message to his/her users.
Below is the complete advisable code to make connection with PhpMyAdmin and with Database
After writing the above code in the notepad save it with .php extension. When you execute the above code in the browser nothing will be displayed if you get anything displayed in the browser it shows there is any mistake occurred in the code.
You can also write the above code in this way
Note :- The above code is only applicable for wampserver. For your domain username and password may be different.