Wednesday, October 17, 2012

Inserting a data into MySQL Database using PHP

SIMPLE SIGNUP PAGE

Step 1: Creating Database on mysql
  
create database myweb;
create table signup; 
(
fn char(50) not null,
cor char(50) not null,
center char(50) not null,
dob date,
pn char(50));

fn stands for first name,
cor stands for course,
center stands for institution name,
dob stands for date of birth,
pn stands for parents name.

Step 2: HTML Signup Page

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
 <html xmlns="http://www.w3.org/1999/xhtml">  
 <head>  
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
 <title>Untitled Document</title>  
 </head>  
 <body>  
 <form method="post" action="update.php">  
 <table width="424" height="353" >  
  <tr>  
   <th height="49" colspan="3" scope="col">STUDENT SIGN UP</th>  
  </tr>  
  <tr>  
   <td width="31" height="250">&nbsp;</td>  
   <td width="344"><table width="418" >  
    <tr>  
     <td>NAME</td>  
     <th width="146" scope="col"><input type="text" name="name" id="textfield" /></th>  
     <th width="62" scope="col">&nbsp;</th>  
    </tr>  
    <tr>  
     <td>COURSE</td>  
     <td><input type="text" name="cor" id="textfield2" /></td>  
     <td>&nbsp;</td>  
    </tr>  
    <tr>  
     <td>CENTER</td>  
     <td><input type="text" name="center" id="textfield3" /></td>  
     <td>&nbsp;</td>  
    </tr>  
    <tr>  
     <td>DATE OF BIRTH</td>  
     <td><input type="text" name="dob" id="textfield4" /></td>  
     <td>&nbsp;</td>  
    </tr>  
    <tr>  
     <td>PARENTS NAME</td>  
     <td><input type="text" name="pn" id="textfield5" /></td>  
     <td>&nbsp;</td>  
    </tr>  
    <tr>  
     <td>&nbsp;</td>  
     <td><input type="submit" name="button" id="button" value="Sign Up" /></td>  
     <td>&nbsp;</td>  
    </tr>  
   </table></td>  
   <td width="27">&nbsp;</td>  
  </tr>  
  <tr>  
   <td height="44" colspan="3">&nbsp;</td>  
  </tr>  
 </table>  
 </form>  
 </body>  
 </html>  



                                                          
 Step 2: PHP INSERTING Page

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
 <html xmlns="http://www.w3.org/1999/xhtml">  
 <head>  
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
 <title>Untitled Document</title>  
 </head>  
 <?php  
 $name=$_POST[name];  
 $cor=$_POST[cor];  
 $center=$_POST[center];  
 $dob=$_POST[dob];  
 $pn=$_POST[pn];  
 $con = mysql_connect("localhost","root","");  
 if (!$con)  
  {  
  die('Could not connect: ' );  
  }  
 mysql_select_db("hari", $con);  
 $sql="INSERT INTO signup(NAME,cor,center,dob,pn)  
 VALUES  
 ('$_POST[name]','$_POST[cor]','$_POST[center]','$_POST[dob]','$_POST[pn]')";  
 if (!mysql_query($sql,$con))  
  {  
  die('Error: ' . mysql_error());  
  }  
 echo "1 record added";  
 mysql_close($con);  
 ?>   
 <table border="1" style="position:absolute;  
 left:100px;  
 top:150px;">  
  <tr>  
   <td colspan="2"><div align="center">Registered Successfully</div></td>  
  </tr>  
  <tr>  
   <td width="238">Name is</td>  
   <td width="72"><?php echo $name; ?></td>  
  </tr>  
  <tr>  
   <td>Course is;</td>  
   <td><?php echo $cor; ?></td>  
  </tr>  
  <tr>  
   <td>Center is</td>  
   <td><?php echo $center; ?></td>  
  </tr>  
  <tr>  
   <td>Date of Birth is;</td>  
   <td><?php echo $dob; ?></td>  
  </tr>  
  <tr>  
   <td>Parent Name;</td>  
   <td><?php echo $pn; ?></td>  
  </tr>  
 </table>  
 </body>  
 </html>  

NOW TRY YOUR OWN...ALL THE BEST
dd

Friday, September 28, 2012

Joomla 1.6 or 1.7 or 2.5 above Installation steps

Step 1: Download Joomla


Step 2: Extract the joomla zip file to HTDOCS or www folder

Step 3: Rename the folder to Joomla , Example:C:\wamp\www\Joomla

Step 4: Open the URL of the newly-uploaded Joomla script. If the content is uploaded in the main web 
            directory
Step 5: Select the language eg: english(us) click next


Step 6: On the next page Joomla will check whether the system requirements are met on the server. If one 
             or  more are not met, a corresponding message will be shown.


Step 7:After you make sure that all system requirements are met, proceed by clicking on the Next button 
            from the top right menu. On the next page you should read and accept Joomla's license.

Step 8:  Here you have to enter the MySQL details for the new Joomla 2.5 installation.,so you have to     
             create database
Step 9: Create database eg: myjoomlasite,fill the entries and click next button

Step 10: FTP Configuration ,this step is  optional , Click NEXT Button


Step 11: Main Configuration ,pecify your site name, meta description and keywords, admin user, email and 
               password.,  If you are new to Joomla you should also CLICK Install the Sample Content, this will  
                help with learning about Joomla.Click next button to proceed



Step 12:  Is the final step. Joomla is now installed! You must now remove the installation directory, this needs to 
                be removed for security reasons to prevent anyone else from coming along and reinstalling Joomla 
                over your existing site. Click the Remove Installation Directorybutton.





Monday, August 20, 2012

PHP Scalar Data Types

A data type identifies the characteristics that the assigned data will be interpreted by when interacting with
the PHP programming language. When a value is assigned a specific data type, the PHP interpreter will
work with the data based on the expected type of data it is. For example, 27654 could be considered a
numeric data type or it could be considered a string data type, such as in the zip code for a customer. Even
though you could perform mathematical equations on the zip code, it would make no sense to do so. Thus,
zip codes, even though they look like they would be numeric numbers should be identified as a string data
type to eliminate problems such as zip codes that start with zero (ex. 08102). Assigning the correct data
type to the expected value is an important part of working with PHP. There are three categories of data
types in PHP: Scalar, Compound and Special.



Scalar Data Types
A scalar data type is identified as being able to hold
one value at a time. In PHP, there are four data
types that fall into this category.

• Boolean - A boolean value is a truth value, either 'true' or 'false', often coded 1 and 0, respectively.
When a value is assigned the Boolean data type, there are only two responses that the value can be
assigned: True (1) or False (0). If a value is assigned anything other than these two values, it will
default to True (1).
 <?php  
 $Wealthy = false; // $Wealthy is false  
 $Wealthy = 1; // $Wealthy is true  
 $Wealthy = 5; // $Wealthy is true  
 $Wealthy = -1; // $Wealthy is true  
 $Wealthy = 0; // $Wealthy is false  
 ?>  
A Boolean Value is either TRUE or FALSE typed in either upper or lower case and should not be in quotes.
Try the following program:

 <?php  
   $var0 = true;  
   $var1 = false;  
   $var2 = TRUE;  
   $var3 = FALSE;  
   echo $var0."<br />";  
   echo $var1."<br />";  
   echo $var2."<br />";  
   echo $var3."<br />";  
 ?>  

If you tried the above program, you would have noticed that no value was displayed for false; do not worry about that.Boolean values are usually the result of operators in conditionals like the if-condition. Read and try the following program:

 <?php  
   if (true)  
     {  
       echo "It is true indeed."."<br />";  
     }  
   if (5==5)  
     {  
       echo "5==5 as a condition with the operator, ==, returns TRUE."."<br />";  
     }  
 ?>  
TRUE or FALSE are Boolean literals. There are other literals that are equivalent to TRUE or FALSE. That is what we look at in this section.

The following returned values are equivalent to FALSE:

- the boolean FALSE itself
- the integer 0 (zero)
- the float 0.0 (zero)
- the empty string (""), and the string "0"
- an array with zero elements
- the special type NULL (including unset variables) – See later
- SimpleXML objects created from empty tags – See later

The following returned values are equivalent to TRUE:
- Any literal or data type that is not in the above list is equivalent to TRUE.
--------------------------------------------------------------------------------------------------------------
• Integer - An integer is a whole numeric data type (meaning it does not contain any fractions) that
can be set to decimal (base 10), octal (base 8) or hexadecimal (base 16). The following
demonstrate some of the values that can be assigned the numeric data type:
 <?php  
 $Temperature = 22; // $Temperature is an integer  
 $x = -45672; // $x is an integer number  
 $y = 0642; // $y is an integer number (octal)  
 $z = 0x5E5B; // $z is an integer number (hexadecimal)  
 ?>  

The maximum number that can be assigned to an integer is based on the system. 32 bit systems
have a maximum signed integer range of -2147483648 to 2147483647. The maximum signed
integer value for 64 bit systems is 9223372036854775807. Any value that exceeds the maximum
integer size will be assigned the float data type.

• Float - Floating point numbers are any number that has a fractional component or exceed the
integer maximum values. This data type is also referred to as floats, doubles or real numbers.
Floats are used to represent such numbers as monetary values, distances, weights, scientific
notations and a host of other values:
 <?php  
 $TotalCost = 67.25; // $TotalCost is a float  
 $Distance = 4.5e5; // $Distance is a float equal to 450000  
 $Weight = 92.0; // $Weight is a float  
 $Diff = 2.34E+12; // $Diff is a float (2340000000000)  
 ?>  

The size of a floating point number is dependent by the system being used. In addition, floating
point numbers are not as accurate as integer numbers when it comes to precision. Even simple
numbers like 0.2 and 0.17 can not be converted into their binary equivalents without a loss of
precision. With that said, floating point numbers should never be used in comparison operations
without building in logic such as rounding numbers prior to the comparison operation or using a
tolerance value that would be an acceptable difference between the compared values for
comparison operations.

• String - A string data type is a series of characters that are associated with each other in a defined
order. There is no limit to the length of a string data value. The following represent some of the
values that can be assigned to a string data type:

 <?php  
 $Name = 'Jose Vargás'; // $Name is a string  
 $Value = '£45.20'; // $Value is a string  
 $Location = "subway\n"; // Contains a character return  
 $x = "This is a 'test'"; // $x is a string  
 $Chapter = '1.2.4' // $Chapter is a string  
 ?>  


The characters that can be used in PHP string data types are limited to the ISO 8859-1 or Latin-1
character set. This character set allows for 256 (the size of a byte) different possible characters
(191 of them that are actually printable); however, there is support in PHP to encode strings to the
UTF-8 standard (UTF-8 is a standard mechanism used by Unicode for encoding wide character
values into a byte stream).


PHP Array

These are a series of like values that are assigned to an individual variable with each individual value in the array being referenced with a unique identifier. Once these values are stored into an array, it is possible to retrieve individual values or to perform multiple actions against the stored values. The following demonstrates the storing and retrieval of an array set:

An array can be used when we want a single variable to hold multiple values. Values in arrays can be accessed by using the index associated to it. Each element in the array has its own index. Default start of index starts from 0. Arrays are useful when you want to store a group of data.

Array Example 1
 <?php  
 $Country[0] = "Australia"; // Australia is the first(0) value  
 $Country[1] = "Russia"; // Russia is the second(1) value  
 $Country[2] = "Germany"; // Germany is the third(2) value  
 $Country[3] = "France"; // France is the fourth(3) value  
 // The following will display: Let's go to Germany!  
 print "Let's go to $Country[2]!";  
 ?>  
Demo

The above example could be written less explicitly:

 <?php  
 $Country = array("Australia", "Russia", "Germany", "France");  
 print "Let's go to $Country[2]!";  
 ?>  
Demo

Array Example 2

Rather than using numeric identifiers, array identifiers can be more meaningful when created as in
the following examples:
 <?php  
 $Capital["Australia"] = "Canberra";  
 $Capital["Russia"] = "Moscow";  
 $Capital["Germany"] = "Berlin";  
 $Capital["France"] = "Paris";  
 print "The capital of Russia is ".$Capital["Russia"]."!";  
 ?>  
 <?php  
 $Capital = array(  
 "Australia" => "Canberra",  
 "Russia" => "Moscow",  
 "Germany" => "Berlin",  
 "France" => "Paris");  
 print "The capital of Russia is ".$Capital["Russia"]."!";  
 ?>  
Demo

Array Example 3

 <?php   
                // defining a simple array  
                $array1 = array(4,8,15,16,23,42);  
                // referencing an array value by its index  
                echo $array1[0];  
                // arrays can contain a mix of strings, numbers, even other arrays  
                $array2 = array(6,"fox", "dog", array("x", "y", "z"));  
                // referencing an array value that is inside another array  
                echo $array2[3][1];  
           ?>  
           <br />  
           <?php  


Demo

Array Example 4

 <?php   
                // defining a simple array  
                $array1 = array(4,8,15,16,23,42);  
                // referencing an array value by its index  
                echo $array1[0];  
                // arrays can contain a mix of strings, numbers, even other arrays  
                $array2 = array(6,"fox", "dog", array("x", "y", "z"));  
                // referencing an array value that is inside another array  
                echo $array2[3][1];  
           ?>  
           <br />  
           <?php  

Demo

Array Example5

 <?php  
                // You can also assign labels to each pocket (called "keys"),  
                $array3 = array("first_name" => "Kevin", "last_name" => "Skoglund");  
                // which will allow you to use the key to reference the value in that array position.  
                echo $array3["first_name"] . " " . $array3["last_name"] . "<br />";  
                $array3["first_name"] = "Larry";  
                echo $array3["first_name"] . " " . $array3["last_name"] . "<br />";  
           ?>  

Demo

Array Example 6


        <?php  
                // Changing values in an array that has already been defined  
                // It's just like variables but you use the index to reference the array position  
                $array2[3] = "cat";  
                echo $array2[3];  
           ?>  

Demo


 

Wednesday, August 15, 2012

Starring php Basics



  • // single-line comments can be like this
  • # or even like this
  • /* multi-line comments can be like this */
  •  ; The semicolon at the end of the statement is important! 
  • the PHP command echo is a means of outputting text to the web browser

Comparison chart


Echo (PHP)Print (PHP)
Parameters:echo can take more than one parameter when used without parentheses. The syntax is echo expression [, expression[, expression] ... ]. Note that echo ($arg1,$arg2) is invalid.print only takes one parameter.
Return value:echo does not return any valueprint always returns 1 (integer)
Syntax:void echo ( string $arg1 [, string $... ] )int print ( string $arg )
What is it?:In PHP, echo is not a function but a language construct.In PHP, print is not a really function but a language construct. However, it behaves like a function in that it returns a value.

The print() function is slightly slower than echo().

Example:

<html>
<head>
<title>Hello World! PHP</title>
</head>
<body>

<h1>Examples</h1>
<?php echo "Hello World!"; ?>
<br />



<?php
// print works like echo
print "Hello World!";
?>
<br />

<?php
// concatenation
echo "Hello" . " World!<br />";

// simple math
echo 2 + 3;

?>
<br />
</body>
</html>

About php Variables

  • variable is used for storeing information
  • All variables in PHP are denoted with a leading dollar sign ($)
  • PHP does a good job of automatically converting types from one to another when necessary.

Code:
<html>
<head>
<title>About php Variables</title>
</head>
<body>
<?php
$a = "hello";
$hello = "Hello everyone.";
echo $a ."<br />";
echo $hello."<br />";

echo $$a."<br />";



?>
</body>
</html>

phpinfo()

What is phpinfo?

PHPinfo is a function that returns information, in HTML form, about the PHP environment on your server.


phpinfo() outputs plain text instead of HTML when using the CLI mode.


<?php

/* WARNING: NEVER include this file on your production machine

It's very useful for development but it also gives away WAY too much

information about your system if anyone got access to it.

*/

phpinfo();

?>