Posts

Showing posts from November, 2014

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>

Writing a file using PHP

<?php $filename = "jyoti.txt"; $file = fopen( $filename, "w" ); if( $file == false ) {    echo ( "Error in opening new file" );    exit(); } fwrite( $file, "naveen rajput\n" ); fclose( $file ); ?> <html> <head> <title>Writing a file using PHP</title> </head> <body> <?php if( file_exist( $filename ) ) {    $filesize = filesize( $filename );    $msg = "File  created with name $filename ";    $msg .= "containing $filesize bytes";    echo ($msg ); } else {    echo ("File $filename does not exit" ); } ?> </body> </html>

date(); function in php

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

Count Example in PHP

<?php function MyCounter() {   $count=0;  echo $count;  $count++; } MyCounter(); ?>

Use Of Define Function In PHP

<?php define("A","Naveen rajput"); define("B","Naveen"); define("C"," rajput"); echo A; echo '<br/>'; echo B; echo '<br/>'; echo C; ?>

Associative array in PHP

<?php $a = array(0=>"naveen",1=>"Rajput",2=>"Naveen Rajput"); echo $a[0]."<br/>"; echo $a[1]."<br/>"; echo $a[2]; ?>

Add Two Number in PHP

<?php function Add() { $a=10; $b=20; $c=$a+$b; echo $c; } Add(); ?>

array in php

<?php $a=array(1,2,3); echo $a[0]; echo $a[1]; print $a[2]; ?>

Php Database Connection.

<?php $con=mysql_connect("localhost or ip address","username","password"); //select the database mysql_select_db("database-name",$con); ?>

Image Height and Width Validation through Javascript.

Image
<html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script type="text/javascript"> function readImage(file) {     var reader = new FileReader();     var image  = new Image();     reader.readAsDataURL(file);       reader.onload = function(_file) {         image.src    = _file.target.result;              // url.createObjectURL(file);         image.onload = function() {             var w = this.width,                 h = this.height,                 t = file.type,                           // ext only: // file.type.split('/')[1],                 n = file.name,                 s = ~~(file.size/1024) +'KB';            // $('#uploadPreview').append('<img src="'+ this.src +'"> '+w+'x'+h+' '+s+' '+t+' '+n+'<br>'); if(h<786&&w<1024) { alert('file

login through jsp and servlet.

Image
<!DOCTYPE html> <html>   <meta charset="UTF-8">   <title>Login</title>     <link rel="stylesheet" href="newcss.css" media="screen" type="text/css" /> <head> <meta charset="utf-8"> <title>Login</title>              <script type="text/javascript">             function check()             {                 var a=document.getElementById("name").value;                 var b=document.getElementById("pass").value;                 if(a=="")                 {                 alert("Enter your username!!");                 return false;                 }                 else if(a.length<5)                 {                     alert("Pls fill correct username!!");                 }                 if(b=="")                 {                   alert("Enter