People often question about the initializing task of php, following are the few tasks that help a person get started with coding in php:
Task 1: Required Installations
All you need is an editor and localhost.
Task 2: Static Welcome Message Display
Start your installed (WAMP, LAMP, XAMPP, WAMP) server (Note:If your skype is there online then you need to signout skype for starting your server because of port conflict). Open Notepad++ and create new file at wamp/www for WAMP and applications/MAMP/htdocs for MAMP.
Place the following code in the file:
echo "Hello World";
In your browser goto http://localhost and you will find your file listed there, click on the file and you will see a welcome message “Hello World” there.
tags are there to enclose php code. Echo will print the content.
Task 3: Display Name Dynamically
Previously we have displayed a hardcoded message, now display your name dynamically. W3schools is there for beginners. Just explore the html section and code a basic form.
<form name=”form1″ id=”form1″ action=”" method=”POST">
Enter your name:<input type=”text” name=”uname” id=”uname” />
<input type=”submit” name=”submit” id=”submit”
value=”Save Name” />
$_POST array have all the submitted data of the form.
Refresh the file in the browser and you will see a form, just enter your name and submit it and you will see “Your Name: your_name_here”. Just explore html section of W3schools and play with the layout of your form.
Task 4: Save Data in Database
Now comes interesting part of learning any programming lanaguage i.e. database interaction.
In your browser goto http://localhost, click phpMyAdmin option there.
Lets `user` be the name of your database,` user_info` be the name of your table having fields `name` and `roll_number` (it is auto incremented).
- Here is a tutorial for creating database in phpMyAdmin
- Here is a tutorial for creating table in phpMyAdmin
<form name="form1" id="form1" action="" method="POST">
Enter your name:<input type="text" name="uname" id="uname" />
<input type="submit" name="submit" id="submit"
value="Save Name" />
$con = mysql_connect("localhost",'root','root');
mysql_select_db("user",$con) or die (mysql_error);
$query = "INSERT INTO user_info (name)
mysql_query($query) or die (mysql_error);
Goto your table at phpMyAdmin and refresh the table, you will see your name there.
For listing records, updating and much more functions explore W3Schools SQL section.
This tutorial is there to let you know how simple and easy going php is. Once you are done with these basic tasks you can try modifying the html and php code to learn more.
Have a nice time in the world of php 🙂