I had a custom login form in WP(3.1.2) and the problem i was facing is whenever the form was submitted i used to get empty $_POST array.This was my code
<form method=”post” action=”<?php echo bloginfo(’url’).’/?page_id=221′; ?>”>
After some google search I found the solution which was :
<form method=”post” action=”<?php echo $_SERVER['PHP_SELF'].’/?page_id=221′; ?>”>
which means if you are submitting the form on the same page use $_SERVER else you wont get the data in post
Tags: php, wordpress
Posted in tricks on June 7th, 2011 by dharmesh22>
$data = array(
‘currency’ => $order->getOrderCurrencyCode(),
‘date_added’ => date(’Y-m-d’)
);
$order_query = new stdClass();
$order_query->row = $data;
Tags: oops, php
Posted in tricks on March 15th, 2011 by Karan Ahuja>
I came across a case where i was getting a post in which i get column names of my table in keys, so i used the following code
$data = array(’column_1′ => 1, ’column_2′ => 45, ’column_3′ => 25 );
$sql = http_build_query($data, ”, ‘, ‘);
$query = “UPDATE table_name SET ” . $sql . ” WHERE id = ‘ 24 ‘ ” ;
Note: This cant be used if you values are coming in string
Tags: array, http_build_query, php, sql-query
Posted in tricks on March 15th, 2011 by jimy>
<?php
function exceptions_error_handler($severity, $message,$filename, $lineno) {
throw new ErrorException($message, 0, $severity, $filename, $lineno);
}
set_error_handler(’exceptions_error_handler’);
?>
Tags: php
Posted in tricks on November 29th, 2010 by Manthan>
hi guys,
I came across a beautiful function of php which will convert any php array to the GET parameter for url.
E.g.
$data = array( ‘foo’ => ‘bar’, ‘jimy’ => ‘modi’ );
$url = http_build_query($data);
this will give you
foo=bar&jimy=modi
More info
Tags: php
Posted in tricks on August 27th, 2010 by jimy>
After searching for more than four to five hours i got the link which give latitude, longitude and other information such as address including city and country. So here is a small function which will give you latitude and longitude of the given ip address.
function getLatLng($ip){
//get the contents from the site by file_get_contents.
$sXML = @file_get_contents(’http://ipinfodb.com/ip_query.php?ip=’.$ip.’&timezone=false’);
//make the response in a xml object so we can parse it.
$oXML = @new SimpleXMLElement($sXML);
$array = array(
‘Latitude’ => (string) $oXML->Latitude[0],
‘Longitude’ => (string) $oXML->Longitude[0]
);
return $array;
}
Tags: ip address, latitude, longitude, php
Posted in tricks on August 27th, 2010 by jimy>
Unlike Java , the constructor of the super class will not be called implicitly in PHP .
To call the parent class constructor from the child class we can use :
parent::construct();
Tags: php
Posted in tricks on June 21st, 2010 by Karan Ahuja>
I came across a situation where i want to end an event exactly after two days and before an hour of third day ( i.e. 11:00 pm on third day). After searching on google and checking the date function in php manual i came to this solution
$new_date = ( strtotime(’-1 hour’,strtotime ( ‘+3 day’ , strtotime (date ( ‘Y-m-d’ ) ) ) ));
This will return a unix timestamp which will give you 11:00 pm of third day.
eg. if todays date is 27/05/2010 07:08:15 then it will give you 29/05/2010 23:00:00
Tags: date and time, php
Posted in tricks on May 27th, 2010 by jimy>
if you have a listbox called “department” and want to insert multiple values from the listbox into the database,then:
when the user submits the form,store the value in a variable
$company_dept=$_POST['department'];
query:INSERT into table_name values(’”.join(”,”,$company_dept).”‘)
Tags: mysql, php
Posted in tricks on January 28th, 2010 by dharmesh22>
function isValidEmail($email){
return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]
+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email);
}
Tags: php
Posted in tricks on January 27th, 2010 by jimy>