> January 2013 ~ Online tutorial

delete directory in php

delete directory in php <?php // delete a new directory path rmdir("C:\wamp\www\uploaddata1"); if(rmdir) {     echo "directory removed"; } else {     echo "directory can't removed"; } ?> output:before After the co...

create directory in php

create directory in php Now we are going to create directory that is folder in php.In the PHP we are having mkdir()to create directory. Program <?php // create a new directory path mkdir("C:\wamp\www\uploaddata1"); if(mkdir) {     echo "directory created"; } else {     echo "directory can't created"; } ?> Output In...

read directory php

read directory php <?php // assign folder into variable $currdir='/var/www'; //open the directory for reading $dir=opendir($currdir); //read a filename while($file = readdir($dir) { // Display all file name in the specified folder echo "$file<br/>"; } closedir($dir); }?> Output: index.html est.html first.php Explanation Now opendir...

login form using php

Login form using php Now we are going to create login form by using PHP validation technique.now we are create database for the login called Login then we can use the database . Then we are simple HTML form for get user name and password from the system Program <html> <body> <form name='form1' method="post" action="logo.php">  ...

writes file in php

writes file in php make money In PHP we are using fwrite() function to retrieve data in file.we are using fwrite() function that will return how many character will placed in the file only it is display. html> <body> <?php $content="hello world"; $f=fopen('today.txt','w'); // today.txt must in read.php location $fh=fwrite($f,$content); //...

read file in php

read from file in php the fread() reads from an open file.The function will stop at the end of the file or when it reaches the specified length.whichever comes first.this function the read string or false on failure syntax frad(file,length) Example <html> <body> <?php $f=fopen('today.txt','r'); // today.txt must in read.php location $fh=fread($f,"6"); echo...

Opening a File in php

Opening a File in php The fopen() function is used to open files in PHP. Syntax: fopen('file name','mode of operation') The first parameter of this function contains the name of the file to be opened the second parameter specifies in which mode the file should be opened: <html> <body> <?php $file=fopen("welcome.txt","r");...

update query in php

Update data from Php:   In this tutorial we are show the table value can be update from old one to new one.In this example name in the field value henry will changed to the mathavan Syntax: update table_name set attri_name='value' where attr_value='value to be changed' this syntax for update value in table <?php $conn=mysql_connect("localhost","root",""); $sel=mysql_select_db("proj",$conn); $c...

select query in php

select query in php From the select query in php.we are going to select entire or extract data from the table .we are using mysql_query()to retrieve the data.here example for go to get data from database. ?php $conn=mysql_connect("localhost","root",""); $sel=mysql_select_db("proj",$conn); $c = mysql_query("select * from data"); echo "<table border='1'>"; echo...

insert form data into database php

Insert Data From a Form Into a Database Now we will create an HTML form that can be used to add new records to the "data" table. Here is the HTML form: <html> <body> <form action="in.php" method="post"> Firstname:<input type="text" name="firstname" /> Lastname: <input type="text" name="lastname" /> Age: <input type="text"...

insert query in php

PHP MySQL Insert Into The INSERT INTO statement is used to insert new records into a database table. Insert Data Into a Database Table The INSERT INTO statement is used to add new records to a database table. Syntax INSERT INTO table_name VALUES (value1, value2,....) You can also specify the columns where you want to insert the data: INSERT...

create table in mysql

Create a Table The CREATE TABLE statement is used to create a database table in MySQL. Syntax CREATE TABLE table_name ( column_name1 data_type, column_name2 data_type, column_name3 data_type, ....... ) We must add the CREATE TABLE statement to the mysql_query() function to execute the command. Example The following example shows how you...

Closing a Connection in mysql

Closing a Connection The connection will be closed as soon as the script ends. To close the connection before, use the mysql_close() function. ≤ ?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } // some code mysql_close($con); ?&g...

connecting mysql with php

Connecting to a MySQL Database Before you can access and work with data in a database, you must create a connection to the database. In PHP, this is done with the mysql_connect() function. Syntax mysql_connect(servername,username,password); Parameter Description servername Optional. Specifies the server to connect to. Default value is "localhost:3306" ...

create database in mysql

PHP MySQL Introduction MySQL is the most popular open source database server. What is MySQL? MySQL is a database. A database defines a structure for storing information. In a database, there are tables. Just like HTML tables, database tables contain rows, columns, and cells. Databases are useful when storing information categorically. A company...

die() in php

Basic Error Handling: Using the die() function The first example shows a simple script that opens a text file: <?php $file=fopen("welcome.txt","r"); ?> If the file does not exist you might get an error like this: Warning: fopen(welcome.txt) [function.fopen]: failed to open stream: No such file or directory in C:\webfolder\test.php...

error handling in php

PHP Error Handling The default error handling in PHP is very simple. An error message with filename, line number and a message describing the error is sent to the browser. PHP Error Handling When creating scripts and web applications, error handling is an important part. If your code lacks error checking code, your program may look very unprofessional...

php mail function

PHP Simple E-Mail The simplest way to send an email with PHP is to send a text email. In the example below we first declare the variables ($to, $subject, $message, $from, $headers), then we use the variables in the mail() function to send an e-mail: ?php $to = "someone@example.com"; $subject = "Test mail"; $message = "Hello! This is a simple...

sending mail in php

PHP Sending E-mails PHP allows you to send e-mails directly from a script. The PHP mail() Function . The PHP mail() function is used to send emails from inside a script. Syntax mail(to,subject,message,headers,parameters) Parameter Description to Required. Specifies the receiver / receivers of the email subject Required. Specifies the subject...

destroying session in php

Destroying a Session If you wish to delete some session data, you can use the unset() or the session_destroy() function. The unset() function is used to free the specified session variable: <?php unset($_SESSION['views']); ?>  function: You can also completely destroy the session by calling the session_destroy() <?php session_destroy();...

storing session data php

Storing a Session Variable The correct way to store and retrieve session variables is to use the PHP $_SESSION variable: <?php session_start(); // store session data $_SESSION['views']=1; ?> <html> <body>; <?php //retrieve session data echo "Pageviews=". $_SESSION['views']; ?> </body> </html> Output:...

php session

PHP Sessions A PHP session variable is used to store information about, or change settings for a user session. Session variables hold information about one single user, and are available to all pages in one application. PHP Session Variables When you are working with an application, you open it, do some changes and then you close it. This is...

remove cookie value in php

How to Delete a Cookie? When deleting a cookie you should assure that the expiration date is in the past. Delete example: <?php // set the expiration date to one hour ago setcookie("user", "", time()-3600); ?> What if a Browser Does NOT Support Cookies? If your application deals with browsers that do not support cookies, you will have...

retrieve data from cookie php

How to Retrieve a Cookie Value? The PHP $_COOKIE variable is used to retrieve a cookie value. In the example below, we retrieve the value of the cookie named "user" and display it on a page: <?php // Print a cookie echo $_COOKIE["user"]; // A way to view all cookies print_r($_COOKIE); ?> In the following example we use the isset()...

PHP Cookies

PHP Cookies A cookie is often used to identify a user. What is a Cookie? A cookie is often used to identify a user. A cookie is a small file that the server embeds on the 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. How to Create...

PHP Functions with Return values

PHP Functions - Return values Functions can also be used to return values. Example <html> <body> <?php function add($x,$y) { $total = $x + $y; return $total; } echo "1 + 16 = " . add(1,16) ?> <body> </html> The output of the code above will be: 1 + 16 = 17...

php functions with multiple parameters

PHP Functions - Adding parameters Our first function (writeMyName()) is a very simple function. It only writes a static string. To add more functionality to a function, we can add parameters. A parameter is just like a variable. You may have noticed the parentheses after the function name, like: writeMyName(). The parameters are specified inside...

function in php

PHP Functions The real power of PHP comes from its functions. In PHP - there are more than 700 built-in functions available. PHP Functions: In this tutorial we will show you how to create your own functions. For a reference and examples of the built-in functions. Creating PHP functions: • All functions start with the word "function()" • Name the...