Use of html hidden variables in php

Html hidden variables are very useful in php.

Html hidden controls are used to store values or id's . If we add a
form with this hidden control, values stored in that control can be
passed in post method

php email validation example

Here is the code to validate email address



<?php

if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",$email)){
echo "Invalid email";
}else{
echo "Valid Email";}

?>

create gridviews with sigmawidgets [javascript,ajax]

Sigma grid is Written in pure javascript, Sigma Grid is an Ajax data grid for displaying and inline editing data in a scrollable and sortable table. With MVC architecture, plenty of attributes and powerful script API, this grid control brings developer more flexibilities and less workload.

For more details visit :sigmawidgets

php functions explained -- func_num_args() and func_get_args()

1. func_num_args()
2. func_get_args()

These are two php functions used to find number of arguments passed to a function and get get argument values.

For more details visit php manual

why this functions?

These functions are used in function oveloading to find number of arguments passed and there values. .
Usual method of function overloading not works in php.

Make a div clickable javascript

You can make a div or li tag clickable using javascript


use following code

<div onclick="window.location.href='cc.html'">

Export and import mysql database for webhosting

phpmyadmin provides good interface to upload and download database .








All webhosting sites provides phpmyadmin to upload databases.

Here is interface to export database.It is very simple you can select database or tables to export














You can export database in following formats

1.
2.
3.
4.
5.
6.
7.  
8. 
9. 
10 .
Most commonly database is exported as sql

You can also download database in zipped or gzip format


For importing database browse the databse and save to server through import interface


Pass variables from one page to another

Here is a simple method to Pass variables from one page to another

Here is the code in first page

<a href="page2.php?nam=sree">click here</a>


In your second page you can access variable name as


$name=$_GET['nam'];
echo $name;

This code will display sree

Download files with php script example

Simple code for downloading files

Place this code in a php file and make links to it. That links will be act as download link for the file .





<?php
$filename="left.txt";

$type=filetype($filename);

header("Content-type: $type");
header("Content-Disposition: attachment;filename=$filename");
header("Content-Transfer-Encoding: binary");
header('Pragma: no-cache');
header('Expires: 0');
// Send the file contents.
set_time_limit(0);
//readfile($file);


 ?>

Pass array in php from one php page to other

Here is a simple way to pass your array in post method.

In first page we are creating a form.In that form creating hidden 
controls with arrray value as shown below.

In second part (display.php) we can extract values from request 
variable. 
Here is the code 
 
///////////////////////////////////////////////////

echo '<form name="form" method="post" action="display.php">';


$i=0;

foreach($arr as $key => $value)
{
$i++;
echo '<input type="hidden" name="val['.$i.']" value="'.$value.'"/>';
}

echo '</form>';







////////////////Copde in display.php page ////////////////



foreach($_REQUEST['val'] as $key => $value)
{


echo $value;
}

//////////////////////////////////////

If you found some good method to pass array Share with us as comments 
with regards SREEHARI

Javascript vs jquery

Jquery is a collection of javascript classes .It is very easier than javascript.If you are new to client side scripting you can prefer jquery.

What are the advantages of using Jquery?

Jquery is simple to use.It avoids difficulties in using java script .

You can find simple examples of jquery from
www.w3schools.com


For more details, visit http://jquery.com

Display all get variables using foreach loop

Using following code we can display all get variable passing from a page
<?php

foreach($_GET as $k=>$v)
echo $v;
?>


Same way we can also display all post varibles with their keys

<?php

foreach($_POST as $k=>$v)
echo $v;
?>

My sql error - (You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near)

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near


You can easily find error by identifying remaining part of error .The error in your mysql query is in the first character of the remaining error .

For example error in the following message must be near word "long"

Eg:- "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'long,buy,credit,bankrupt,discharged,forclosure,lforclosure,home_loan,payment,mpa' at line 1"

php error -(Parse error: syntax error, unexpected T_DNUMBER, expecting ',' or ';')

Parse error: syntax error, unexpected T_DNUMBER, expecting ',' or ';'

This error occur when a number comes when expecting a string .
For example the following code produces error because a string is concatenated with integer.


<?php
echo "example".1;
?>

php errors- (Parse error: syntax error, unexpected T_ECHO, expecting ',' or ';')

2. Parse error: syntax error, unexpected T_ECHO, expecting ',' or ';'

This error occurs when a semicolon missing

For example following code produces this error because of missing a semicolon in second line


<php
echo $s
?>

php errors- Parse error: syntax error, unexpected T_ECHO

Errors are very helpful to programmers .When you identifies cause of error next time that error will not be a challenge for you.
Here i am providing some common errors

1.Parse error: syntax error, unexpected T_ECHO

This error is due to some unidentified symbol or character in code

For example following code produces the above error because of "character x" in code

<?php
x
echo "error example";
?>

Study php

Find resources Study php?
You can find basics of php from internet.Some of the helpful sites are
w3schools

php.net

Download xampp

Where you can download xampp/wamp ?

Download xampp

Download wampserver

Phpmyadmin

What is php myadmin?

Phpmyadmin is to control mysql databases for php.It gives a good interface to do operations in databases and tables .Phpmyadmin will be installed with xamp or wamp.You can connect to phpmyadmin from xamp/wamp controlpanel.

All hosting services provides a phpmyadmin interface for uploading and manage your mysql database

php and client side

Php is only a server side scripting.For client side scripting we can use javascript

If you are new in php go to www.w3schools.com/  simple working examples

Start php

How you can start php?
Download and Install Xamp or wamp server in your windows machine to start learning php.
Xamp and wamp are software packages ,it installs apache ,php mysql in your system and provides running environment for php.

You can place your website folder in htdocs(in xamp) or in www(root folder in wamp).


We can also create php by manualy configuring php,mysql and apache. Also we can use iis instead of apache.