simple syntax database connection in php to mysql
<?php
$conn=mysql_connect(servername,username,password);
mysql_select_db("dbname",$conn);
?>
In paramerters like servername is which server to connect database,Username to which username to log in with,Password to which password to log in with.
file uploading in php
file uploading in php
Example of file uploading in php
html part
<html>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
<label for="logo">Filename:</label>
<input type="file" name="logo" id="logo" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
php script
<?php
if ($_FILES["logo"]["error"] > 0)
{
echo "Error: " . $_FILES["logo"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["logo"]["name"] . "<br />";
echo "Type: " . $_FILES["logo"]["type"] . "<br />";
echo "Size: " . ($_FILES["logo"]["size"] / 1024) . " Kb<br />";
echo "Stored in: " . $_FILES["logo"]["tmp_name"];
}
?>
Example of file uploading in php
html part
<html>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
<label for="logo">Filename:</label>
<input type="file" name="logo" id="logo" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
php script
<?php
if ($_FILES["logo"]["error"] > 0)
{
echo "Error: " . $_FILES["logo"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["logo"]["name"] . "<br />";
echo "Type: " . $_FILES["logo"]["type"] . "<br />";
echo "Size: " . ($_FILES["logo"]["size"] / 1024) . " Kb<br />";
echo "Stored in: " . $_FILES["logo"]["tmp_name"];
}
?>
Simple meaning of Ob_start() in Php
This function will used for turn on output buffering.if buffering is ON no output is sent from the script (other than headers) instead the output is stored in an internal buffer.
The contents of this internal buffer copied into a string variable using in ob_get_contents(). To output what is stored in the internal buffer, use ob_end_flush(). ob_end_clean() used for used discard the buffer contents.
example of ob_start():
<?php
ob_start();
?>
<html>
<head>
<title>Ob start </title>
</head>
test
</body>
</html>
<?php
echo ob_get_contents();
?>
it will get output : test test
The contents of this internal buffer copied into a string variable using in ob_get_contents(). To output what is stored in the internal buffer, use ob_end_flush(). ob_end_clean() used for used discard the buffer contents.
example of ob_start():
<?php
ob_start();
?>
<html>
<head>
<title>Ob start </title>
</head>
test
</body>
</html>
<?php
echo ob_get_contents();
?>
it will get output : test test
simple mail in php
simple mail in php
Php used send mail to mail()
syntax:
mail(to,subject,message,headers,parameters)
simple example of php mail
<?php
$test = "test mail";
// Send email
mail("test@examples.com","My subject",$test);
?>
Php used send mail to mail()
syntax:
mail(to,subject,message,headers,parameters)
simple example of php mail
<?php
$test = "test mail";
// Send email
mail("test@examples.com","My subject",$test);
?>
Simple meaning of Session
Session is a variable used to store information about, or change settings for a user session. Session varable hold information about one single user, and are available to all pages in one application.It stores information on the server.
simple meaning of Cookie in Php?
simple meaning of cookie
A cookie is commonly used for identify a user. A cookie is a small file that store user's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.
create cookie
setcookie() function used for set cookie.
syntax of cookie
setcookie(name, value, expire, path, domain);
Example of cookie
<?php
setcookie("test", "Koran", time()+3600);
?>
In the example above, we will create a cookie named "test" and assign the value "Koran" to it.
We also specify that the cookie should expire after one hour:
A cookie is commonly used for identify a user. A cookie is a small file that store user's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.
create cookie
setcookie() function used for set cookie.
syntax of cookie
setcookie(name, value, expire, path, domain);
Example of cookie
<?php
setcookie("test", "Koran", time()+3600);
?>
In the example above, we will create a cookie named "test" and assign the value "Koran" to it.
We also specify that the cookie should expire after one hour:
different types of errors in php
different types of errors in php
1. Notices:
non-critical errors,not displayed to window, for example: variable is not def ind,do not affect the program.
2. Warnings:
serious errors -it displayed to window for example: include() a file which does not found, at the time these errors displayed, but they do not affect the script.
3. Fatal errors:
These are critical errors, affect termination of the script, - for example, instantiating an object of a non-existent class, or calling a non-existent function.
1. Notices:
non-critical errors,not displayed to window, for example: variable is not def ind,do not affect the program.
2. Warnings:
serious errors -it displayed to window for example: include() a file which does not found, at the time these errors displayed, but they do not affect the script.
3. Fatal errors:
These are critical errors, affect termination of the script, - for example, instantiating an object of a non-existent class, or calling a non-existent function.
main difference between include and require in php
Main difference between include and require
In both are same functionality but main difference in error handling.
include() function produces a Warning message on failure,
while require() results in a Fatal Error.
In both are same functionality but main difference in error handling.
include() function produces a Warning message on failure,
while require() results in a Fatal Error.
simple date function in php
simple date function in php
PHP Date() - Format the Date
d - Represents the day of the month (01 to 31)
m - Represents a month (01 to 12)
Y - Represents a year (in four digits)
Example of Simple Date Function
<?php
echo date("Y-m-d")
?>
Result
2009-09-11
PHP Date() - Format the Date
d - Represents the day of the month (01 to 31)
m - Represents a month (01 to 12)
Y - Represents a year (in four digits)
Example of Simple Date Function
<?php
echo date("Y-m-d")
?>
Result
2009-09-11
main difference between get and post in php
main difference between get and post in php
In post method value not shown in url,but get method value shown in url,other main difference is value storing capacity,in get method value and variable are limited,but post method this are unlimited,
get method hidden variables are shown as a part of the URL.but post hidden variable are always hidden.
In post method value not shown in url,but get method value shown in url,other main difference is value storing capacity,in get method value and variable are limited,but post method this are unlimited,
get method hidden variables are shown as a part of the URL.but post hidden variable are always hidden.
post function use in php
Example of POST Function use in php
$_POST function is used for post form values send specifiled headers,it mainly used for submit from value specifield action page,it without shown the value on browser address query.
example of post method:
<html>
<head>
<title>Testing post mehod</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form action="test.php" method="post" name="frm">
<table align="center">
<tr>
<td>
username
</td>
<td>
<input type="text" name="name">
</td>
</tr>
<tr>
<td>
Password
</td>
<td>
<input type="password" name="name">
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" value="submit" name="submit">
</td>
</tr>
</table>
</form>
</body>
</html>
$_POST function is used for post form values send specifiled headers,it mainly used for submit from value specifield action page,it without shown the value on browser address query.
example of post method:
<html>
<head>
<title>Testing post mehod</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form action="test.php" method="post" name="frm">
<table align="center">
<tr>
<td>
username
</td>
<td>
<input type="text" name="name">
</td>
</tr>
<tr>
<td>
Password
</td>
<td>
<input type="password" name="name">
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" value="submit" name="submit">
</td>
</tr>
</table>
</form>
</body>
</html>
simple meaning of php array
Simple Meaning of array
Main feauture of array which can store multile value and variable.
Example of Simple Array
<?php
$cars=array("Saab","Volvo","BMW","Toyota");
print_r($cars);
?>
Main feauture of array which can store multile value and variable.
Example of Simple Array
<?php
$cars=array("Saab","Volvo","BMW","Toyota");
print_r($cars);
?>
concatenation operators in php
concatenation Operator in php
It is used to two string values together.
Example of Concatenation Operator in Php
<?php
$t1="Welcome!";
$t2="Php";
echo $t1 . " " . $t2;
?>
it will get : Welcome Php
It is used to two string values together.
Example of Concatenation Operator in Php
<?php
$t1="Welcome!";
$t2="Php";
echo $t1 . " " . $t2;
?>
it will get : Welcome Php
simple string declaration in php
String variables are used for values that contains characters.
Example of String Declaration
<?php
//single quotes declaration
echo 'this is a single quotes declaration';
//double quotes declaration
echo "this is a single quotes declaration'';
?>
Example of String Declaration
<?php
//single quotes declaration
echo 'this is a single quotes declaration';
//double quotes declaration
echo "this is a single quotes declaration'';
?>
simple variable declaration in php
Simple Defenition of php variable
Variables used to storing a values,text strings,numbers or arrays.
When a variable is declared, it can be used over and over again in your script.
All variables in PHP start with a $ sign symbol.
Example of declaring a variable in PHP
<?php
$var="test";
echo $var;
it returns :test
?>
Variables used to storing a values,text strings,numbers or arrays.
When a variable is declared, it can be used over and over again in your script.
All variables in PHP start with a $ sign symbol.
Example of declaring a variable in PHP
<?php
$var="test";
echo $var;
it returns :test
?>
comment word in php
comment word in php
Php Mainly used two types of comment tag
(1) Single line Comment.
(2) Multi line Comment.
Single line Comment
Example of Single line Comment
<?php
//test
?>
Example of Multi line Comment
<?php
/*
line1
line2
line3
*/
?>
Php Mainly used two types of comment tag
(1) Single line Comment.
(2) Multi line Comment.
Single line Comment
Example of Single line Comment
<?php
//test
?>
Example of Multi line Comment
<?php
/*
line1
line2
line3
*/
?>
simple syntax of Php
Bacic Syntax of Php
php Start with <?php and ends with ?>
Example of php print a word
<?php
echo "Welcome to php";
?>
php Start with <?php and ends with ?>
Example of php print a word
<?php
echo "Welcome to php";
?>
php support databases
Php Support So many database like MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC,but commenly used Mysql
php support operating systems
php support operating systems
PHP Support on different operating System(Windows, Linux, Unix, etc.)
PHP Support on different operating System(Windows, Linux, Unix, etc.)
Subscribe to:
Posts (Atom)