Posts

Showing posts with the label PHP Advanced

How to connect with MySQL database using PHP

Connecting to MySQL database is very easy. To do this you have to follow some basic steps. Here are the steps:  Create a connection for MySQL database Select the Database Close the Database Create a connection for MySQL database: To do this you can use mysql_connect() function. This function is used to connect with MySQL database. mysql_connect() function takes three parameter. The first parameter is serverName, second parameter serverUsername and the last parameter is serverPassword. We can write this function like this  mysql_connect(serverName, serverUsername, ServerPassword)   We use Vertigo server. In Vertrigo server the serverName is localhost, the serverUsername is root and the serverPassword is vertrigo so we can write the function like this  mysql_connect(localhost, root, vertrigo)  Note: In ZAMMP server there are no password is needed so the server password could be null.  The real PHP code to connect with MySQL database like this  <?php...

PHP include_once statement

PHP include_once statement is very similar to PHP include statement but the only difference is include_once statement include PHP file only one time in any page. On the other hand, PHP include statement include a file many times.   Structure:   The structure of PHP include_statement is                          include_once("FileName")                              include_once("function.php") Example: Suppose that, we have three PHP file where first one has a function that print 0 to 10. Second PHP file include the first file and show the output. The third one add those two file. Now the code snippet are  first.php <?php function foo() {     for($variable=0; $variable<10;$variable++)  ...

PHP include statement

Sometimes we need to re-use same code in different PHP files such as Header file . We use same header file in different page. For that reason we need to write same code in different page. It is time consuming and not good way of writing PHP code. To solve this problem we use PHP include() statement. PHP include() statement Structure Now the question is how we use PHP include() statement in our code. We use include syntax to add same type of code. Suppose that, we want to add header.php file in register.php file. We write include("header.php") in the register.php file. So the structure of include() statement is                         include("file name or file path")                  include ("header.php")       PHP include statement example Think that we have a file name title.php that show the title in header...

Passing variable values from URL with PHP Get method

Today we look at how can we sent variable data from one page to another page through url. In real life web application we need to send data from one page to another page.  To do this, we will open two pages. First page contains a URL with variable value and second page collects that value using PHP $_GET method. We name the first page is first_page.php and second page is second_page.php.  So the first page looks like this <a href="second_page">Second Page</a> Save this page in your localhost folder. This is a HTML URL example page. Now we see how to send data from url. To do this you need to put a question mark in the URL and then you need to write your variable with values. Now the page is <a href="second_page?name=Sharif">Second Page</a> In this portion we just set one value but in real life problem we need to send two or more values from url. To send two or more values you need to set & operator after each variable. So the page is <...