Thursday, December 26, 2013

when we redirect pages using header to got warning in php[solved]

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs

<?php
    ob_start();
?>
<html>
    <!-- Output -->
</html>
<?php
    session_start();
    ob_flush();
?>

try this like  code standard to avoid warning when using header function and redirection the pages

Wednesday, August 14, 2013

How to get/read data from xml file using jquery?

Code: 

$.ajax({
type: "GET",
url: "book.xml",
dataType:"xml",
success: function(xml) {
$(xml).find('attributes').each(function(){
var bg=$(this).find('background').text();
});
}
});

Explanation: Using this you can get the datas from the xml file.

How to remove unnecessary space between lines(coding in page) using dreamweaver?


  1. Open the file
  2. Click CTRL + F
  3. Select "Current document" in "Find in" (You can also select the folder if you have multiple files)
  4. Search in "Source code"
  5. Tick "Use regular expression"
  6. Type "[\r\n]{2,}" (without quotes) in "Find"
  7. Type "\n" (without quotes) in "Replace"
  8. Press "Replace All"

Saturday, July 27, 2013

Simple script of using ajax to insert data into database

Hi friends,

ajax.php

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="js/jquery.min.js"></script>
</head>
<script type="text/javascript">
function ajaxrequest()
{
    var name1=$("#name").val();
    var age1=$("#age").val();
    var datastring='name='+name1+'&age='+age1;

       $.ajax({
             type: "POST",
             url: "sample.php",
             data:datastring,
             cache:false,
             beforeSend: function()
             {
                 $("#signup_status").html("please wait");
             },
             success:function(response)
             {
                 alert(response);
                 $("#signup_status").html(response)
             }
            
      
      
      
      
        });
   
   
   
}

</script>

<body>
<div>
name:<input type="text" name="name" id="name" />
age:<input type="text" name="age" id="age" />
<input type="button" name="submit"  value="submit" onclick="ajaxrequest()"/>
<div id="signup_status"></div>

</div>

 --------------------------------------------------------------------------
sample.php

<?php
$hostname="localhost";
$username="root";
$password="root";
$database="practise";
$conn= mysql_connect($hostname,$username,$password) or die('could not connect');
$db=mysql_select_db($database) or die('database could not connect');
 $name=$_POST['name'];
 $age=$_POST['age'];

$qry="INSERT INTO test (name,age)VALUES ('$name','$age')";
         $result=mysql_query($qry) or die('query does not work');
         if($result!="")
         {
            echo "records inserted" ;
         }
         else
         {
             echo "records not inserted" ;
         }
       

?>

--------------------------------------------------------------------------------
tables:-

Field            Type
name            varchar(25) NOT NULL
 age              int(10) NOT NULL




Tuesday, April 23, 2013

Function of erag and eragi and solution of deprecated warnings.

PHP Function ereg():

Syntax

int ereg(string pattern, string originalstring, [array regs]);

Definition and Usage

The ereg() function searches a string specified by string for a string specified by pattern, returning true if the pattern is found, and false otherwise. The search is case sensitive in regard to alphabetical characters.
The optional input parameter regs contains an array of all matched expressions that were grouped by parentheses in the regular expression.

Return Value

  • It returns true if the pattern is found, and false otherwise.

Example

Following is the piece of code, copy and paste this code into a file and verify the result.
";
}
else
{
   echo "Could not found a .com
";
}
$retval = ereg(("(\.)(com$)"), $email_id, $regs);
if( $retval == true )
{
   echo "Found a .com and reg = ". $regs[0];
}
else
{
   echo "Could not found a .com";
}
?>
This will produce following result
Found a .com
Found a .com and reg = .com


PHP Function eregi()

Syntax

int eregi(string pattern, string string, [array regs]);

Definition and Usage

The eregi() function searches throughout a string specified by pattern for a string specified by string. The search is not case sensitive. Eregi() can be particularly useful when checking the validity of strings, such as passwords.
The optional input parameter regs contains an array of all matched expressions that were grouped by parentheses in the regular expression.

Return Value

  • It returns true if the pattern is validated, and false otherwise.

Example

Following is the piece of code, copy and paste this code into a file and verify the result.

This will produce following result
Invalid password! Passwords must be from 8 - 10 chars


warnings and solutions:-

function ereg() is deprecated:

solution: ereg() is replace into preg_match and add "/" at start and end.
 otherwise use "~"
exp:-

 if (!preg_match("/^<([a-zA-Z1-9]{1,$maxElem}) *(.*)>$/", $p_tag, $reg)) return false;

eragi_replace into preg_replace.

otherwise simply call this function in your page :-

error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);

 


 

Monday, April 15, 2013

Format Date Fields Using MySQL DATE_FORMAT()

MySQL DATE_FORMAT() Example

DATE_FORMAT(NOW(),'%W, %M %e, %Y @ %h:%i %p')
#yields 'Sunday, September 20, 2008 @ 12:45 PM'

MySQL DATE_FORMAT() Letter Representations

SpecifierDescription
%aAbbreviated weekday name (Sun..Sat)
%bAbbreviated month name (Jan..Dec)
%cMonth, numeric (0..12)
%DDay of the month with English suffix (0th, 1st, 2nd, 3rd, …)
%dDay of the month, numeric (00..31)
%eDay of the month, numeric (0..31)
%fMicroseconds (000000..999999)
%HHour (00..23)
%hHour (01..12)
%IHour (01..12)
%iMinutes, numeric (00..59)
%jDay of year (001..366)
%kHour (0..23)
%lHour (1..12)
%MMonth name (January..December)
%mMonth, numeric (00..12)
%pAM or PM
%rTime, 12-hour (hh:mm:ss followed by AM or PM)
%SSeconds (00..59)
%sSeconds (00..59)
%TTime, 24-hour (hh:mm:ss)
%UWeek (00..53), where Sunday is the first day of the week
%uWeek (00..53), where Monday is the first day of the week
%VWeek (01..53), where Sunday is the first day of the week; used with %X
%vWeek (01..53), where Monday is the first day of the week; used with %x
%WWeekday name (Sunday..Saturday)
%wDay of the week (0=Sunday..6=Saturday)
%XYear for the week where Sunday is the first day of the week, numeric, four digits; used with %V
%xYear for the week, where Monday is the first day of the week, numeric, four digits; used with %v
%YYear, numeric, four digits
%yYear, numeric (two digits)
%%A literal “%” character
%xx, for any “x” not listed above