Posts

Php file inclusion.

PHP provides two function for file inclusion. include. require. include(). Include take all text from file and it copies into the file that uses the include function.if there is problem of loading a file then include generate a warning but script run. require(). Include take all text from file and it copies into the file that uses the include function.if there is problem of loading a file then reqiure function generates falt error and halt the execution of script.

Diffrence Between Get and Post

This Used to send info to client end to server end. Get. get method to produce a long string which append in server log,in browser location box. get method is restrict to send only 1024 char only. get method provides $_GET associative array to access all sent info. example--http://namaskarstore.com/products-list.php?subid=&catid=8&bid=&sizes=&range=&colors=red Post . Post method does not have restriction for data size. post method used for send ASCII as well as binary data. data send by post goes through http header so security depends on http protocol. Post provides $_POST associative array to access all sent info. 

set cookie through jquery in php

 <script type="text/javascript"> $(document).ready(function() {     $("#currency").change(function() { var id = $(this).val();         $.ajax({             url: 'current.php',             type: 'POST',             data:{'id':$(this).val()},             success: function(data)             {         location.reload();             }         });     }); }); </script> current.php <?php $id=$_POST['id']; setcookie("to",$id); ?>

add to cart function in php which is call on add to cart button.

<?php function addtocart($pid,$q,$psize,$blouse,$sizeee,$petticot,$petticotsize,$presttiched){ if($pid<1 or $q<1) return; if(is_array($_SESSION['cart'])){ if(product_exists($pid)) return; $max=count($_SESSION['cart']); $_SESSION['cart'][$max]['productid']=$pid; $_SESSION['cart'][$max]['qty']=$q; $_SESSION['cart'][$max]['size']=$psize; $_SESSION['cart'][$max]['blouse']=$blouse; $_SESSION['cart'][$max]['sizeee']=$sizeee; $_SESSION['cart'][$max]['petticot']=$petticot; $_SESSION['cart'][$max]['petticotsize']=$petticotsize; $_SESSION['cart'][$max]['presttiched']=$presttiched; } else{ $_SESSION['cart']=array(); $_SESSION['cart'][0]['productid']=$pid; $_SESSION['cart'][0]['qty']=$q; $_SESSION['cart'][0]['size']=$ps

Remove .php extension in PHP through .htaccess file.

RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php

Add product with images upload in php.

<?php include("adminpanel.php"); include("Database.php"); $sql="select * from department"; $sql1="select * from brand"; $sql2="select * from bridge_type"; $sql3="select * from face_shape"; $sql4="select * from facial_features"; $sql5="select * from frame_type"; $sql6="select * from framematerial"; $sql7="select * from hinge_type"; $sql8="select * from lens_type"; $sql9="select * from frame_color"; ?> <html> <head> <script src="ckeditor/ckeditor.js" type="text/javascript"></script> <script src="js/jquery-1.8.2.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script type="text/javascript"> function random() { var generator = Math.floor(Math.random()*1000000);      var ss="TUL

Send Html Newsletter with php through mail Function.

<?php $a=$_POST["nemail"]; if($ret) { //header("location:newsletter.php"); $to = $a; // subject $subject = 'Thank you For Subscribe your Domain name NewsLetter'; // message $message = '<table width="100%" border="0" cellspacing="0" cellpadding="3" style="font-family:Trebuchet MS, Arial, Helvetica, sans-serif; font-size:12px; border:#F63 1px solid;">   <tr style="background:url(http://your Domain name /images/second_bg.png) 52% 50% no-repeat #1D0100;height:180px;">     <td align="center" height="105" width="161"><img src="http://your Domain name /images/logo.png" height="105" width="161" border="0" /></td>   </tr>   <tr>     <td><table width="70%" border="0" align="center" cellpadding="3" cellspacing="0" st

Upload image and create its xml through php.

<?php $name=$_POST["name"]; $title=$_POST["title"]; $filename = $_FILES["file"]["name"]; $filename1 = $_FILES["file1"]["name"]; $filename2 = $_FILES["file2"]["name"]; $filename3 = $_FILES["file3"]["name"]; $filename4 = $_FILES["file4"]["name"]; $filename5 = $_FILES["file5"]["name"]; $filename6 = $_FILES["file6"]["name"]; $filename7 = $_FILES["file7"]["name"]; $filename8 = $_FILES["file8"]["name"]; $path="img/$filename"; $path1="img/$filename1"; $path2="img/$filename2"; $path3="img/$filename3"; $path4="img/$filename4"; $path5="img/$filename5"; $path6="img/$filename6"; $path7="img/$filename7"; $path8="img/$filename8"; $fill=$_FILES["file"]["tmp_name"]; $fill

Read text from file in php

<html> <head> <title>Reading a file using PHP</title> </head> <body> <?php $filename = "naveen.txt"; $file = fopen( $filename, "r" ); if( $file == false ) {    echo ( "Error in opening file" );    exit(); } $filesize = filesize( $filename ); $filetext = fread( $file, $filesize ); fclose( $file ); echo ( "File size : $filesize bytes" ); echo ( "<pre>$filetext</pre>" ); ?> </body> </html>

session in php this example show how to set session in php.

<?php session_start(); $_SESSION['u']=$_post['name']; $_SESSION['p']=$_post['pass']; echo "welcome".$_SESSION['u']."<br/>"; echo "ur password is".$_SESSION['P']; ?>

String Handling in php

<?php $string1="Hello World"; $string2="1234"; echo $string1 . " " . $string2; ?>

date function in php

<?php echo date("dS F Y h:i:s A",strtotime("Today")); ?>

get record from database in textfield with php

<html> <body> <?php $a=$_GET['uid']; echo "$a"; $con=mysql_connect("localhost","root","root"); if(!con) { die("could not connect".mysql_error()); } $sql="select * from department where id='".$a."'"; mysql_select_db('naveen',$con); echo "naveen"; $qry = mysql_query( $sql); echo "<table border='2'>"; echo "<form action='update.php' method='POST'>"; echo "naveen"; while($r=mysql_fetch_array($qry)) {  $id=$r["id"];  $name=$r["name"];  $pass=$r["password"];  $mail=$r["emailid"]; echo "<tr>"; echo "<td><input type='hidden' name='i' value='".$id."'/></td><br/>"; echo "<td><input type='text' value='".$name."' name

Update record using PHP

<?php $a=$_POST['i']; //echo "$a"; $b=$_POST['n']; //echo "$b"; $c=$_POST['p']; //echo "$c"; $d=$_POST['e']; //echo "$d"; $con=mysql_connect("localhost","root","root"); if(!con) { die("could not connect".mysql_error()); } $sql="update department set name='".$b."',password='".$c."',emailid='".$d."' where id='".$a."'"; mysql_select_db('naveen',$con); $ok=mysql_query($sql); if(!ok) { die("could not updated".mysql_error()); } else { echo "data is successfully updated"; echo "<a href='view.php'>view</a>"; } ?>

get record from database through PHP

<html> <body> <?php $con=mysql_connect("localhost:3306","root","root"); //echo "$con"; if(!con) { die('could not connect'.mysql_error()); } $sql="select * from department";   mysql_select_db('naveen',$con); $qry = mysql_query( $sql); //echo "naveen";  echo "<table border='2'>  <tr> <th>ID</th><th>NAME</th><th>PASSWORD</th><th>EMAILID</th><th>DELETE</th><th>ERASE</th> </tr>" ; while($retval=mysql_fetch_array($qry)) { echo "<tr>"; echo "<td>$retval[0]</td>"; echo "<td>$retval[1]</td>"; echo "<td>$retval[2]</td>"; echo "<td>$retval[3]</td>"; echo "<td><a href='del.php?did=$retval[0]'>delete</a></td>"; echo "<td>