Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Friday, August 7, 2009

Invalid default value for 'logTime'

Process of database restoration using the following SQL query :

CREATE TABLE `smf_log_online` (
SESSION varchar( 32 ) NOT NULL default '',
logTime timestamp default 'CURRENT_TIMESTAMP' ,
ID_MEMBER mediumint( 8 ) unsigned NOT NULL default 0,
ip int( 10 ) unsigned NOT NULL default 0,
url text NOT NULL default '',
PRIMARY KEY ( SESSION ) ,
KEY logTime( logTime ) ,
KEY ID_MEMBER( ID_MEMBER )
) TYPE = MYISAM


There is a massive problem occur, The following message:

" #1067 - Invalid default value for 'logTime' "


For this problem you need to change SQL statement to get it to work following:

remove '' from '
CURRENT_TIMESTAMP' ..

CREATE TABLE `smf_log_online` (
SESSION varchar( 32 ) NOT NULL default '',
logTime timestamp default CURRENT_TIMESTAMP ,
ID_MEMBER mediumint( 8 ) unsigned NOT NULL default 0,
ip int( 10 ) unsigned NOT NULL default 0,
url text NOT NULL default '',
PRIMARY KEY ( SESSION ) ,
KEY logTime( logTime ) ,
KEY ID_MEMBER( ID_MEMBER )
) TYPE = MYISAM


Wednesday, March 12, 2008

How to Create a PHP Calendar

How to Create a PHP Calendar
with Don Schechter


PHP calendars can be used for everything from simply displaying the date to creating complex reservation systems. See the steps to starting your own PHP calendar.

Display date and time with PHP

Display date and time with PHP
Example:

$b = time ();
print date("g:i:s A D, F jS Y",$b);

Output: 02:10:10 PM Tue, March 12th 2008

PHP Date/Time Variables

If you're looking to customize your date/time display, here are the variables to use:

Days
d - day of the month 2 digits (01-31)
j - day of the month (1-31)
D - 3 letter day (Mon - Sun)
l - full name of day (Monday - Sunday)
N - 1 = Monday, 2 = Tuesday, etc. (1-7)
S - suffix for date (st, nd, rd)
w - 0 = Sunday, 1 = Monday (0-6)
z - day of the year (1 = 365)


Week
W - week of the year (1-52)


Month
F - Full name of month (January - December)
m - 2 digit month number (01-12)
n - month number (1-12)
M - 3 letter month (Jan - Dec)
t - Days in the month (28-31)


Year
L - leap year (0 no, 1 yes)
o - ISO-8601 year number (e.g. GMT, CST)
I - daylight savings (1 = yes, 0 = no)
O - offset GMT (e.g. 0200)
Z - offset in seconds (-43200 - 43200)
r - full RFC 2822 formatted date

Friday, November 23, 2007

PHP The $_POST variable

`PHP $_POST`

The $_POST variable is used to collect values from a form with method="post".

The $_POST variable is used to collect values from a form with method="post". Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.

Example

HTML: test.html









When the user clicks the "Submit" button, the URL will not contain
any form data, and will look something like this:
 http://admincmd.blogspot.com/login.php

The "login.php" file can now use the $_POST variable to catch the form data (notice that the names of the form fields will automatically be the ID keys in the $_POST array):

PHP: login.php

< ?php
echo "Your name is ".$_POST["name"]
;

echo "Your password is ".$_POST["pass"];

?>

Why use $_POST?

  • Variables sent with HTTP POST are not shown in the URL
  • Variables have no length limit

However, because the variables are not displayed in the URL, it is not possible to bookmark the page.

Monday, August 20, 2007

PHP - Session variable

session : An abstract concept to represent a series of HTTP requests and responses exchanged between a specific Web browser and a specific Web server. Session concept is very useful for Web based applications to pass and share information from one Web page (request) to another Web page (request).
Since the current design of HTTP protocol does not support session concept, all Web server side scripting technologies, including PHP, have designed their own way to support session concept. The key design element of session support is about how to identify a session and how to maintain the session ID (identification). One common way to maintain the session ID is use the cookie technology. The following diagram shows you how to do this:

Server Browser
ID created <-- Request #1 ---
<--- Response #1 --> ID kept as cookie
<-- Request #2 ---> ID send back to server
<--- Response #2 -->
<-- Request #3 --- >ID send back to server
<--- Response #3 -->
......

The session concept should be managed by the server. When the first request comes from a browser on a client host, the server should create a new session, and assigns a new session ID. The session ID will be then send back to the same browser as a cookie. The browser will remember this ID, and send the ID back to the server in the subsequent requests. When the server receives a request with a session ID in them, it knows this is a continuation of an existing session.
When the server receives a request from a browser on a new client host (request without a session ID), the server should not only create a new session ID, it should also create a new session object associated with the new session ID. This session object should become the storage place for different requests of the same session to store and share information.
If there is no subsequent request coming back for a long time for a particular session ID, that session should be timed out. After the session has been timed out, if the browser comes back again with the associated session ID, the server should give an invalid session error.

EXAMPLE:

/* Create new session */
session_start();

/*set session parameter */
session_register("var");
$_SESSION["var"]="test session";

echo $_SESSION["var"];
test session

/*clear session */
session_unregister("var");
unset($_SESSION);
session_destroy();

Sunday, August 19, 2007

PHP - Convert digit to thai word

thaimoney_convert.php
============================

<<

function convert($number){

$txtnum1 = array('ศูนย์','หนึ่ง','สอง','สาม','สี่','ห้า','หก','เจ็ด','แปด','เก้า','สิบ');
$txtnum2 = array('','สิบ','ร้อย','พัน','หมื่น','แสน','ล้าน'); $number = str_replace(",","",$number);
$number = str_replace(" ","",$number); $number = str_replace("บาท","",$number);
$number = explode(".",$number);
if(sizeof($number)>2){
return 'ทศนิยมหลายตัวนะจ๊ะ';
exit;
}

$strlen = strlen($number[0]);
$convert = '';

for($i=0;$i<$strlen;$i++){

$n = substr($number[0], $i,1);

if($n!=0){
if($i==($strlen-1) AND $n==1){ $convert .= 'เอ็ด'; }
elseif($i==($strlen-2) AND $n==2){ $convert .= 'ยี่'; }
elseif($i==($strlen-2) AND $n==1){ $convert .= ''; }
else{ $convert .= $txtnum1[$n]; }
$convert .= $txtnum2[$strlen-$i-1];
}
}

$convert .= 'บาท';
if($number[1]=='0' OR $number[1]=='00' OR $number[1]==''){ $convert .= 'ถ้วน'; }
else{ $strlen = strlen($number[1]);
for($i=0;$i<$strlen;$i++){
$n = substr($number[1], $i,1);
if($n!=0){
if($i==($strlen-1) AND $n==1){$convert .= 'เอ็ด';}
elseif($i==($strlen-2) AND $n==2){$convert .= 'ยี่';}
elseif($i==($strlen-2) AND $n==1){$convert .= '';}
else{ $convert .= $txtnum1[$n];}
$convert .= $txtnum2[$strlen-$i-1];
}
}
$convert .= 'สตางค์';
}
return $convert;
}
$x = '5,121.10 บาท';

echo $x.' => '.convert($x);

?>


Thursday, August 9, 2007

PHP - get client ip address

Function can get client ip address using this function :)

//-----------------------------------------------

function getIP() {
$ip;
if (getenv("HTTP_CLIENT_IP"))
$ip = getenv("HTTP_CLIENT_IP");
else if(getenv("HTTP_X_FORWARDED_FOR"))
$ip = getenv("HTTP_X_FORWARDED_FOR");
else if(getenv("REMOTE_ADDR"))
$ip = getenv("REMOTE_ADDR");
else
$ip = "UNKNOWN";
return $ip;


}

//-----------------------------------------------

Usage:
<

$client_ip=getIP();
echo "Your IP :".$client_ip;
?>

//--------------------------------------------