Tizag.com Webmaster Tutorials - A collection of webmaster tutorials from HTML to PHP.

Sunday, August 31, 2008

Java Script: Allow only Numeric Value, Decimal

function allowOnlyNumeric(e) {

var bName = navigator.appName; //alert(bName);

if(bName == "Microsoft Internet Explorer"){

var key_ie = window.event.keyCode;

//alert(key_ie);

if ( (key_ie > 47 && key_ie < 58) || key_ie == 46 || key_ie == 32 || key_ie == 45 )

return;

else

window.event.returnValue = null;

}else{

var key_mozila = e.which;

//alert(key_mozila);

if ( (key_mozila > 47 && key_mozila < 58) || key_mozila == 46 || key_mozila == 32 || key_mozila == 45 )

return;

else

return false;

}

}

onkeypress="javascript:return allowOnlyNumeric(event);"

Saturday, August 23, 2008

MySQL from Command Prompt

The following tutorial assumes that you already have downloaded and installed MySQL on your Windows machine. From inside Windows here’s how you would access MySQL this way:
1) launch a command window by going to: START->ALL PROGRAMS->ACCESSORIES->COMMAND PROMPT
[NOTE: you can also get to it by going to START->RUN and typing: cmd ]
2) inside the Command Prompt window type: cd c:\mysql\bin
(or change directory to the location that you installed if you didn’t use the default install location)
3) if you don’t have a password set yet, then you can set it easily by typing the following:
mysqladmin -u root password new_password
where new_password is the new password that you would like to use
4) next, when you have already set a custom MySQL root password (step #3) then type: mysql -u root -p
PROBLEM #1: if you receive a message asking for your password then enter the custom password (you’ll see asterisk instead of the password). If for some reason you can’t figure out the password you can reset it by following the instructions here: http://dev.mysql.com/doc/mysql/en/Resetting_permissions.html
PROBLEM #2: If you receive a message that indicates the MySQL server isn’t running then you can start the MySQL service from within the Command Prompt by entering the following: net start mysql — you can also see a list of all running NET services by typing: net start
5) next, if the MySQL server is running and you entered in your password correctly you should now be set to communicate directly with the MySQL server from the Command Prompt just like you would if you were telnet or SSH to MySQL on a server. The command prompt should look like this now:
mysql>
You can now view your available database by typing: show databases

Wednesday, August 6, 2008

Page rendering time in PHP

function utime(){
$time = explode( " ", microtime());
$usec = (double)$time[0];
$sec = (double)$time[1];
return $sec + $usec;
}

/*...........on the top of the page................*/
$start = utime();

/*..........bottom of the page before the bolo.......*/
$end = utime();
$run = $end - $start;
echo "<!--

Page created in: " .
substr($run, 0, 5) . " seconds.

-->";