jquery add and remove elements

jquery add and remove elements

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>jQuery Test on - phpsimpleqa.blogspot.com</title>
<script type="text/javascript"   src="http://jobanjohn.googlepages.com/jquery.js"></script>
<script type="text/javascript">
function addNewToPhpqa() {
         var id = $('#idVal').val();
         id++;
          // set a maximum value for elements
          if(id<10){
                   $("#phpsimpleqaToAppend").append("<p id='count" + id + "'><label for='txt" + id + "'>Field " + id + "&nbsp;&nbsp;<input type='text' size='20' name='txtName[]' id='txtName" + id + "'>&nbsp;&nbsp<a href='javascript:void(0);' onClick='removeThisFromPhpsimpleqa("+ id +");'>Remove this</a><p>");
          }else{
          alert("you have reached maximum Thanks phpsimpleqa.blogspot.com");
          }
          $('#idVal').val(id);
}

function removeThisFromPhpqa(id) {
         $("#count"+id).hide(1000);
         // or u can use
         //$("#count"+id).remove();
}
</script>

<body>
<p><a href="javascript:void(0);" onClick="addNewToPhpqa();">Add More</a></p>
<form action="#" method="get" id="phpqa">
<input type="hidden" id="idVal" value="1">
<div id="phpsimpleqaToAppend">
<p id='count1'>
<label for="txt1">
Field 1
&nbsp;&nbsp;
<input size="20" name="txtName[]" id="txtName1" type="text">
&nbsp;&nbsp;
<a href="javascript:void(0);"
onclick="removeThisFromPhpsimpleqa(1);">Remove this</a>
</label>
</p>
</div>
<label ></label>
<p><input type="submit" value="Submit" name="submit">
<input type="reset" value="Reset" name="reset"></p>
</span>
</form>
</body>
</html>

add and remove elements with javascript

add and remove elements with javascript

sample page for creating dynamic elements in HTML using Javascript.
For working Please COPY & PASTE in an editor and run it on browser.
Please edit the Js part for modify the code


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>phpsimple add and remove elements with javascript</title>
<meta name="GENERATOR" content="Quanta Plus">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
//Please edit the Js part for modify the code
function show_new()
{
var id=document.getElementById('count').value;
var currentVal = document.getElementById('showTr').innerHTML;
document.getElementById('showTr').innerHTML = currentVal +"<tr><td align=\"center\" width=\"33%\">"+id+"<input type=\"text\" name=\"events_venue_"+id+"\" ></td><td align=\"center\" width=\"33%\"><input type=\"text\" name=\"events_title_"+id+"\" size=\"10\"></td><td align=\"center\" width=\"33%\"><input type=\"radio\" name=\"events_date_"+id+"\">Yes <input type=\"radio\" name=\"events_date_"+id+"\">No</td></tr>";
document.getElementById('count').value = parseInt(id)+1;
}

</script>
</script>
</head>
<body>
<TR>
<TR>
<td align="center" colspan="2"> <a href="javascript:void(0);" onclick="show_new()">add more</a></td>
</TR>
<tr><TD><table id="showTr">
<tr><td align="center" width="33%"><input type="text" name="events_venue" ></TDd><td align=center
width=33%><input type='text' name="events_title" size="10"></td><td align="center" width="33%"><input type="radio" name="events_date">Yes <input type="radio" name="events_date">No</td></tr>
</table>
</TD>
</tr>
<TR>
<td align="center" colspan="2"><input type="hidden" name="count" id="count" value="2"></td>
</TR>
</table>
</body>
</html>

html elements add and remove dynamically with javascript

html elements add and remove dynamically with javascript


sample page for creating dynamic elements in HTML using Javascript.
For working Please COPY & PASTE in an editor and run it on browser.
Please edit the Js part for modify the code


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>html elements add and remove dynamically with javascript</title>
<meta name="GENERATOR" content="Quanta Plus">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
//Please edit the Js part for modify the code
function show_new()
{
var id=document.getElementById('count').value;
var currentVal = document.getElementById('showTr').innerHTML;
document.getElementById('showTr').innerHTML = currentVal +"<tr><td align=\"center\" width=\"33%\">"+id+"<input type=\"text\" name=\"events_venue_"+id+"\" ></td><td align=\"center\" width=\"33%\"><input type=\"text\" name=\"events_title_"+id+"\" size=\"10\"></td><td align=\"center\" width=\"33%\"><input type=\"radio\" name=\"events_date_"+id+"\">Yes <input type=\"radio\" name=\"events_date_"+id+"\">No</td></tr>";
document.getElementById('count').value = parseInt(id)+1;
}

</script>

</head>
<body>
<TR>
<TR>
<td align="center" colspan="2"> <a href="javascript:void(0);" onclick="show_new()">add more</a></td>
</TR>
<tr><TD><table id="showTr">
<tr><td align="center" width="33%"><input type="text" name="events_venue" ></TDd><td align=center
width=33%><input type='text' name="events_title" size="10"></td><td align="center" width="33%"><input type="radio" name="events_date">Yes <input type="radio" name="events_date">No</td></tr>
</table>
</TD>
</tr>
<TR>
<td align="center" colspan="2"><input type="hidden" name="count" id="count" value="2"></td>
</TR>
</table>
</body>
</html>

simple php programs

simple php programs


ex1:print a word

<?php
echo "test";
?>

ex2:add two numbers
<?php
$a=50;
$b=100;
echo $c=$a+b;
?>
ex3: print date


<?PHP
$date = Date("l - F d, Y");
print("Hello World<BR />\n");
print("Today's date is: $date\n");
?>
ex4:simple email program
<?php
$to = "test@example.com";
$subject = "simple email";
$message = "Hello! This is a simple email message.";
$from = "test1@example.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
ex5:using switch function
<?php
switch ($x)
{
case 1:
  echo "Number 1";
  break;
case 2:
  echo "Number 2";
  break;
case 3:
  echo "Number 3";
  break;
default:
  echo "No number between 1 and 3";
}

 simple file uploading program in php
?>

php function to validate email address

php function to validate email address 
function checkEmail($email) {
  if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])
  ↪*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/",
               $email)){
    list($username,$domain)=split('@',$email);
    if(!checkdnsrr($domain,'MX')) {
      return false;
    }
    return true;
  }
  return false;

php function to get current date

php function to get current date

Date() function can use to current date get in php
example

<?php
echo date("Y/m/d") . "<br />";
echo date("Y.m.d") . "<br />";
echo date("Y-m-d")
?>
The output of the code above could be something like this:
2010/01/11
2010.01.11
2010-01-11

php function to delete file

php function to delete file

unlink function can use Delete a file in php

example unlink function

<?php
$fh = fopen('check.html', 'a');
fwrite($fh, '<h1>Hello world!</h1>');
fclose($fh);

mkdir('checkdir', 0777);

unlink('
check.html');
unlink('checkdir');
?>



function to reverse a string in php

function to reverse a string in php

<?php
echo strrev("Hello world!"); // outputs "!dlrow olleH"
?>

php function to prevent sql injection

php function to prevent sql injection

Injection Prevention - mysql_real_escape_string()

Lucky for you, this problem has been known for a while and PHP has a specially-made function to prevent these attacks. All you need to do is use the mouthful of a function mysql_real_escape_string.
What mysql_real_escape_string does is take a string that is going to be used in a MySQL query and return the same string with all SQL Injection attempts safely escaped. Basically, it will replace those troublesome quotes(') a user might enter with a MySQL-safe substitute, an escaped quote \'.
Lets try out this function on our two previous injection attacks and see how it works.

MySQL & PHP Code: 

//NOTE: you must be connected to the database to use this function!

// connect to MySQL $name_bad = "' OR 1'"; $name_bad = mysql_real_escape_string($name_bad); $query_bad = "SELECT * FROM customers WHERE username = '$name_bad'"; echo "Escaped Bad Injection: <br />" . $query_bad . "<br />"; $name_evil = "'; DELETE FROM customers WHERE 1 or username = '"; $name_evil = mysql_real_escape_string($name_evil);

$query_evil = "SELECT * FROM customers WHERE username = '$name_evil'";
echo "Escaped Evil Injection: <br />" . $query_evil;

Display:

Escaped Bad Injection:
SELECT * FROM customers WHERE username = '\' OR 1\''
Escaped Evil Injection:
SELECT * FROM customers WHERE username = '\'; DELETE FROM customers 
WHERE 1 or username = \''
Notice that those evil quotes have been escaped with a backslash \, preventing the injection attack. Now all these queries will do is try to find a username that is just completely ridiculous:
  • Bad: \' OR 1\'
  • Evil: \'; DELETE FROM customers WHERE 1 or username = \'
And I don't think we have to worry about those silly usernames getting access to our MySQL database. So please do use the handy mysql_real_escape_string() function to help prevent SQL Injection attacks on your websites. You have no excuse not to use it after reading this lesson!

php function to get current date

php function to get current date
<?php
$tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y"));
echo "Tomorrow is ".date("Y/m/d", $tomorrow);
?>

php function to create a file

php function to create a file

$ourFileName = "testFile.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);

php function to remove html tags

php function to remove html tags

/**
*Remove HTML tags, including invisible text such as style and
* script code, and embedded objects.  Add line breaks around
* block-level tags to prevent word joining after tag removal.
*/
function strip_html_tags( $text )
{
    $text = preg_replace(
        array(
          // Remove invisible content
            '@<head[^>]*?>.*?</head>@siu',
            '@<style[^>]*?>.*?</style>@siu',
            '@<script[^>]*?.*?</script>@siu',
            '@<object[^>]*?.*?</object>@siu',
            '@<embed[^>]*?.*?</embed>@siu',
            '@<applet[^>]*?.*?</applet>@siu',
            '@<noframes[^>]*?.*?</noframes>@siu',
            '@<noscript[^>]*?.*?</noscript>@siu',
            '@<noembed[^>]*?.*?</noembed>@siu',
          // Add line breaks before and after blocks
     '@</?((address)|(blockquote)|(center)|(del))@iu',
    '@</?((div)|(h[1-9])|(ins)|(isindex)|(p)|(pre))@iu',
    '@</?((dir)|(dl)|(dt)|(dd)|(li)|(menu)|(ol)|(ul))@iu',
    '@</?((table)|(th)|(td)|(caption))@iu',
    '@</?((form)|(button)|(fieldset)|(legend)|(input))@iu',
    '@</?((label)|(select)|(optgroup)|(option)|(textarea))@iu',
    '@</?((frameset)|(frame)|(iframe))@iu',
        ),
        array(
            ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
     "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0",
            "\n\$0", "\n\$0",
        ),
        $text );
    return strip_tags( $text );
}

function to remove special characters in php

function to remove special characters in php

<?php
# This function makes any text into a url frienly
# This script is created by wallpaperama.com
function clean_url($text)
{
$text=strtolower($text);
$code_entities_match = array(' ','--','&quot;','!','@','#','$','%','^','&','*','(',')','_','+','{','}','|',':','"','<','>','?','[',']','\\',';',"'",',','.','/','*','+','~','`','=');
$code_entities_replace = array('-','-','','','','','','','','','','','','','','','','','','','','','','','','');
$text = str_replace($code_entities_match, $code_entities_replace, $text);
return $text;
}
?>

php simple tutorial

php simple tutorial

function to check password length in php

function to check  password length in php

function checkpassword_length($pass){
$len=strlen($pass);
if($len>=6 && $len<16){
return false;
}else{
return true;
}
}

function to cropping an image in php

function to cropping an image in php

function cropImage($picture,$fixedwidth,$fixedheight,$mogrify) {

// GET IMG
$img = imagecreatefromjpeg($picture);
$width= imagesx($img);
$height= imagesy($img);
// CROP WIDTH
if($width!=$fixedwidth){
$ratio =$fixedwidth/$width;
$NewHeight=round($height*$ratio);
$NewWidth=round($width*$ratio);
exec( $mogrify." -resize ".$NewWidth."x".$NewHeight."! $picture");
exec( $mogrify." -crop ".$fixedwidth."x".$fixedheight."+0+0 $picture");
// REFRESH
$img = imagecreatefromjpeg($picture);
$width= imagesx($img);
$height= imagesy($img);
}
// CROP HEIGHT
if($height!=$fixedheight){
$ratio =$fixedheight/$height;
$NewHeight=round($height*$ratio);
$NewWidth=round($width*$ratio);
exec( $mogrify." -resize ".$NewWidth."x".$NewHeight."! $picture");
exec( $mogrify." -crop ".$fixedwidth."x".$fixedheight."+0+0 $picture");
}
//
ImageDestroy($img);
}
Bookmark and Share

function to find file size in php

function to find file size in php

function ByteSize($bytes)
{
$size = $bytes / 1024;
if($size < 1024)
{
$size = number_format($size, 2);
$size .= ' KB';
}else {
if($size / 1024 < 1024) {
$size = number_format($size / 1024, 2);
$size .= ' MB';
} else if($size / 1024 / 1024 < 1024) {
$size = number_format($size / 1024 / 1024, 2);
$size .= ' GB';
}
}
return $size;
}

.htaccess file and URL rewrite rule in php

.htaccess file and URL rewrite rule in php

htaccess is the default name for a file that is used to indicate
who can or cannot access the contents of a specific file directory from the Internet or an
intranet. The .htaccess file is a configuration file that resides in a directory and
indicates which users or groups of users can be allowed access to the files
contained in that directory.It may also contain some rewrite rules which say
the server to access a page in it if the URL on the browser address bar satisfies
any of the rewrite rules on .htaccess file. A sample .htaccess file
all requests to whatever.htm will be sent to whatever.php:
DirectoryIndex index.php

order allow,deny
deny from all

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\.htm$ $1.php [NC]

Lets rewrite our Example URLs the .htaccess file content will be like this
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\.htm$ $1.php [NC]
RewriteRule ^topics/(.+)/([0-9]+)/(.+)/([0-9]+)/$ http://%{SERVER_NAME}/index.php?sec=$2&id=$4 [nc]

Here the SEO URL
http://www.culblog.com/topics/seo-techniques/4/generate-seo-friendly-url/23
will be rewrited to
http://www.culblog.com/index.php?sec=4&id=23
http://culblog.com/index.php?sec=2&id=5

sample programs in php

sample programs in php

ex1:print a word

<?php
echo "test";
?>

ex2:add two numbers
<?php
$a=50;
$b=100;
echo $c=$a+b;
?>
ex3: print date


<?PHP
$date = Date("l - F d, Y");
print("Hello World<BR />\n");
print("Today's date is: $date\n");
?>
ex4:simple email program
<?php
$to = "test@example.com";
$subject = "simple email";
$message = "Hello! This is a simple email message.";
$from = "test1@example.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
ex5:using switch function
<?php
switch ($x)
{
case 1:
  echo "Number 1";
  break;
case 2:
  echo "Number 2";
  break;
case 3:
  echo "Number 3";
  break;
default:
  echo "No number between 1 and 3";
}

 simple file uploading program in php
?>

list of php sample programs

list of php sample programs
ex1:print a word

<?php
echo "test";
?>

ex2:add two numbers
<?php
$a=50;
$b=100;
echo $c=$a+b;
?>
ex3: print date


<?PHP
$date = Date("l - F d, Y");
print("Hello World<BR />\n");
print("Today's date is: $date\n");
?>
ex4:simple email program
<?php
$to = "test@example.com";
$subject = "simple email";
$message = "Hello! This is a simple email message.";
$from = "test1@example.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
ex5:using switch function
<?php
switch ($x)
{
case 1:
  echo "Number 1";
  break;
case 2:
  echo "Number 2";
  break;
case 3:
  echo "Number 3";
  break;
default:
  echo "No number between 1 and 3";
}

 simple file uploading program in php
?>

how can attach a file to email in php

attach a file to an email message

file attach to an email message,we have to create a multipart MIME message. -Pass these headers as the fourth parameter to mail(): MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=”php-12345″ Note the boundary on the end of the Content-Type.The boundary is an arbitrary US-ASCII string that tells MUAs when the end of a MIME block has been reached. -The first part of the message string should be a plain text message.

Note the boundary marker after the message which tells MIME that we’ve reached the end of this particular part of the email message. -The second part of the “message string ” should be the message itself.We need to add Content-Type and Content-Transfer-Encoding headers to the message, followed by the message itself.

We have to put the boundary marker after at the end of each part of the message. -Next come the attachments. Each attachment gets added to the “message” string as well. We need to add Content-Type and Content-Transfer-Encoding headers, and then the attachment.


example of attach file through mail

<?php
$fileatt = ""; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
$fileatt_name = ""; // Filename that will be used for the file as the attachment

$email_from = ""; // Who the email is from
$email_subject = ""; // The Subject of the email
$email_txt = ""; // Message that the email has in it

$email_to = ""; // Who the email is too

$headers = "From: ".$email_from;

$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);

$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";

$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message . "\n\n";

$data = chunk_split(base64_encode($data));

$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";

$ok = @mail($email_to, $email_subject, $email_message, $headers);

if($ok) {
echo "<font face=verdana size=2>The file was successfully sent!</font>";
} else {
die("Sorry but the email could not be sent. Please go back and try again!");
}
?>

difference between ‘==’ and ‘===’ operators in php

difference between ‘==’ and ‘===’ operators in php


‘= =’ operator tests the equivalence of two entities while  ‘= = =’ operator also tests data type

php simple programs

php simple programs

ex1:print a word

<?php
echo "test";
?>

ex2:add two numbers
<?php
$a=50;
$b=100;
echo $c=$a+b;
?>
ex3: print date


<?PHP
$date = Date("l - F d, Y");
print("Hello World<BR />\n");
print("Today's date is: $date\n");
?>
ex4:simple email program
<?php
$to = "test@example.com";
$subject = "simple email";
$message = "Hello! This is a simple email message.";
$from = "test1@example.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
ex5:using switch function
<?php
switch ($x)
{
case 1:
  echo "Number 1";
  break;
case 2:
  echo "Number 2";
  break;
case 3:
  echo "Number 3";
  break;
default:
  echo "No number between 1 and 3";
}

 simple file uploading program in php
?>

list of php interview questions and answers

list of php interview questions and answers

list of simple interview questions in php

list of simple interview questions in  php

list of interview questions and answers in php

list of interview questions and answers in php

meaning of urlencode and urldecode in php

meaning of  urlencode and urldecode  in php

string urlencode(str)
where str contains a string like this "hello world" and the return value will be URL encoded and can be use to append with URLs, normaly used to appned data for GET like someurl.com?var=hello%world
string urldocode(str)
this will simple decode the GET variable’s value
Like it echo (urldecode($_GET_VARS[var])) will output "Hello world"

use of files frm,.myd, myi in mysql

use of files frm,myd, myi in mysql
rm files store the table definition
MYD files store the data
MYI files store the index

difference between sort(), assort() and ksort in php

difference between sort(), assort() and ksort in php


Sorts an array, sorts an array and maintains index association, Sorts an array by key
Simple sort (sorts on values)
Simple sort after sorting the array (lets assume size of array is 10) rearranges the index, if we want to access element at index[5], using a simple sort an element value would have changed, but in assort the value is still held by index 5 though its position in the array may be 10th.
Ksort – sorts the array by key and maintains the key to data correlations

difference between strpos and stripos

difference between strpos and stripos
strpos is case sensitive search, and stripos is case insensitive search

difference between foo() & @foo()

difference between foo() & @foo()

foo() executes the function and any parse/syntax/thrown errors will be displayed on the page.

@foo() will mask any parse/syntax/thrown errors as it executes.

You will commonly find most applications use @mysql_connect() to hide mysql errors or @mysql_query. However, I feel that approach is significantly flawed as you should never hide errors, rather you should manage them accordingly and if you can, fix them.

list of functions in php

list of functions in php

list of mysql functions

list of mysql functions

list of arrays in php

 list of arrays in php
  • Numeric array - An array with a numeric index
  • Associative array - An array where each ID key is associated with a value
  • Multidimensional array - An array containing one or more arrays

how can connect database in php

how can connect database in php

freelancer php in kerala

freelancer php in kerala

DScom

arun alex
email:dscomtvm@gmail.com
phone:09142162258
http://dscom.000a.biz/

freelance web developer in kerala

freelance web developer in kerala

DScom
arun alex
email:dscomtvm@gmail.com
phone:09142162258
http://dscom.000a.biz

meaning of extract in php

meaning of extract in php
import variables into the current symbol table from an array
example of extract
<?php
$a='original';
$my_array=array("a"=>"cat","b"=>"dog","c"=>"Horse");
extract($my_array);
echo "\a=$a;\$b=$b;\$c=$c";
it will be ouput
$a=cat;$b=dog;$c=$c;
?>