|Language:||English, Spanish, Arabic|
|Genre:||Academic & Education|
|Distribution:||Free* [*Sign up for free]|
Apache is the name of our web server wherein it will handle all the files as well as serve as the communication to the web browser and MySQL is our database which will store all of our information.
Open up your web browser and in the address bar, type localhost. If it's the first time you run it, it will ask what language would you prefer, just simply pick and it will lead you to the menu. Now let's try running the website you just placed. It should be the same as the picture below. If you will notice that the URL is MyFirstWebsite, it is derived from the htdocs folder and it automatically reads files that are named "index" Be it index.
You can also create your custom name for the URL by simply renaming the folder but let's just stick to MyFirstWebsite. Note: If you don't have a file named index and you entered the URL, you will receive an error for not having the file on the server.
If you do have different files that are not named index. Creating the public HTML Pages Next, let's re-modify our website and add a registration link where our users can register as well as a Log-in page right after getting registered. Let's modify our home page with the following code: index. Let's create the registration page first: register.
Now for the login page: Hint: Just copy-paste the same code to make things faster. Click here for the complete login.
Creating the database and it's tables Now that we have our basic page for the public. Let's proceed to the database. Just leave the Collation as is. You have just successfully created your first database. Now from there, let's create a table wherein we can register our users and display information. Adding users to the database Now that we have our tables. Let's move on to the fun part, getting your registration page into action.
From your registration. Click here for the form method reference.
This just simply gets the input based on the name from the form. In our case it's username and password. This ensures that your strings don't escape from unnecessary characters.
Click here to learn more about SQL Injections. Now try to go to your register. In my case I placed in the username xtian and password as It should display the inputs below.
Here's my sample: On this part, you should have understood on how to get input from the form. Now to add it to the database. On your register. The default username is root and no password for default. Click here for some SQL query samples. The again, i'm not here to discuss about mySQL. It is placed in a while loop so that it would query all rows.
Take note that only 1 row is queried per loop that's why a while loop is necessary. It is represented as an array. Try the inputs that you have made earlier and see what happens. It should prompt that you have successfully registered. Try going to phpmyadmin and see your users table: Congratulations!
Now you know how to add data into the database with data validations. User log-in: Authentication Now for the login page. Let's create a new file called checklogin.
The reason is going back to our login. An important note: Like all other PHP commands, functions echo and print are not case sensitive. Instead, you create them once and use the shortcuts when you need them.
Much of this PHP cheat sheet is devoted to that. After that, everything between the curly braces is what the function does when called.
Variables and Constants Similarly to most other programming languages, PHP lets you work with variables and constants. These are pieces of code that store different kinds of information. Defining Variables To do anything with variables, you first need to define them. They must have at least one digit and no decimal point. Can be in decimal, hexadecimal or octal. Floats — This is the name for numbers with a decimal point or in exponential form.
Strings — This simply means text, we will talk about it in detail further below.
Arrays — Arrays are variables that store several values. We will talk about them in detail further below.
Objects — Objects store both data and information on how to process it. Resources — These are references to functions and resources outside of PHP. There is no need to declare PHP variables in a certain way.
They automatically take on the type of the data they contain. Variable Scope Variables can be available in different scopes, meaning the part of a script you can access them. This can be global, local and static. Any variable declared outside of a function is available globally. That means it can be accessed outside of a function as well. If you declare a variable inside a function, it will have a local scope.
The consequence is that it can only be accessed within that function. A way around this is to prepend a local variable with global.