RSS

[php][html] For Beginners

26 Oct

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:

<?php
echo "Hello World";
?>

OR

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” />

</form>

<?php

if(isset($_POST['submit']))

echo $_POST['uname'];

?>

$_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" />

</form>

<?php

$con = mysql_connect("localhost",'root','root');
//host, user,password

mysql_select_db("user",$con) or die (mysql_error);

if(isset($_POST['submit']))

{

$query = "INSERT INTO user_info (name)
VALUES ('".$_POST['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 🙂

Advertisements
 
4 Comments

Posted by on October 26, 2011 in php

 

Tags: , , , , , ,

4 responses to “[php][html] For Beginners

  1. arifamalik

    November 21, 2011 at 7:04 am

    nyc

     
  2. tan

    December 26, 2012 at 3:26 pm

    asalam o alaikum.. just wntd to ask i want to connect my java server to mysql databse dat i’v created using wamp browser.. how do i do it ? thnku 🙂

     
    • Sidra Sultana

      December 26, 2012 at 3:30 pm

      W Salam. I havent tried connecting java server to phpmyadmin, you can google over it

       

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: