Sai Gopal Wordpress Blog

saigopal wordpress blog

Saigopal's website

Saigopal's website

My Daughter Website

Weebly

Palwow

Freelance Jobs

Thursday, October 28, 2010

F5 key board key disable code using javascript

// F5 key board key disable code using javascript
// refresh button in browser also disabling using this following javascript code
//-------------------------------------------------------------------------------------------------
function disablekeyboardnavigation(e)
{
var input_key = "";


if(window.event) {
input_key = event.keyCode; //IE
} else {
input_key = e.which; //firefox
}
if (input_key == 0 ) //F5
{
alert('This operation is not allowed');
return false;
}


return true;
}
// in html body tag place the following code
// body onLoad="disablekeyboardnavigation(this);"
//-------------------------------------------------------------------------------------------------

Wednesday, October 20, 2010

displaying html stored in mysql using php

The tutorial explains the MySQL query to set up the table and then displays the following MySQL code:

CREATE TABLE template (template_id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY, Head_Open VARCHAR(60), Head_Close VARCHAR(60), Page_End VARCHAR(60), Date VARCHAR(60));
CREATE TABLE content (content_id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY, title VARCHAR(60), body MEDIUMBLOB);

Next the author explains and displays the MySQL query to add some data to the tables:

INSERT INTO content (title, body) VALUES ( "MyPage", "This is my sample page, where I will use PHP and MySQL to template my website.
<p> Here is a list of things I like <ul><li>PHP Code</li><li>MySQL</li><li><a href=http://php.about.com>PHP @ About.com</a></li></ul>
<p> That is the end of my content.") ;
INSERT INTO template (Head_Open, Head_Close, Page_End, Date) VALUES ( "<html><head><title>", "</title><body>", "</body></html>",
"$b = time (); print date('m/d/y',$B) . '<br>';");

Next the tutorial explains and displays the following PHP code:

<?php
// Connects to your Database
mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error());
mysql_select_db("Database_Name") or die(mysql_error());

//This retrieves the template and puts into an array. No WHERE clause is used, because we only have one template in our database.
$coding = mysql_query("SELECT * FROM template") or die(mysql_error()); $template = mysql_fetch_array( $coding );

//This retrieves the content and puts into an array. Notice we are calling ID 1, this would change if we wanted to call a page stored on a different row
$text = mysql_query("SELECT * FROM content WHERE content_id =1") or die(mysql_error());
$content = mysql_fetch_array( $text );

//Actually puts the code and content on the page
Print $template['Head_Open'];
Print $content['title'];
Print $template['Head_Close'];

//When pulling PHP code we need to use EVAL
Eval ($template['Date']);

Print $content['body'];
Print $template['Page_End']; ?>

Obviously the script itself is rather well commented and simple to understand each line of code. The author does not, however, show or explain how to actually implement the PHP to display the result as a templated document/webpage. Perhaps the article was written for a more advanced user than myself ;p

Can someone show me how to implement the PHP code please?

I have entered the above PHP code into a file called 'template_001.php'.
No matter how I try to call on this file the result is either a blank white page or the prompt to open/save/edit the php file.
I'm using XAMPP 1.7.3 & Firefox. No changes to the XAMPP or Firefox installation are necessary as ONLY this script is not working. The problem is merely something I'm not doing right in the implementation of the script itself.

I have tried using it as an 'include' & as a 'require', however, I still have no HTML displayed.

The economics of this scripts usefulness is less important than understanding how to use it successfully.

I would be most grateful if anyone could explain how to make this work.

Cheers!

Tuesday, October 19, 2010

PHP FILES

Using the PHP file system function fopen(), we can create a new file. Let's look at this function more closely.
fopen ($filename, $mode);
The function fopen() takes in two arguments, the filename and the mode to either open or create a file.
• $filename - the name of the file. This may also include the absolute path where you want to create the file. Example, "/www/myapp/myfile.txt".
• $mode - mode is used to specify how you want to create the file. For example, you can set the mode to create for read only, or create a file for read and write. Below is the list of possible modes you can use.
PHP file fopen create modes
'w' Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, it attempt to create it.
'w+' Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
'a' Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
'a+' Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
For the list of all modes, please see php site.
Create file
Now let see some examples for creating a new files with fopen for reading and writing.
Example 1 - create new file for writing

The code above creates a new file myfile for writing only in the current directory.
The mode "w" creates a new file for writing, places the pointer in the beginning of the file. If the file already existed, it deletes everything in the file.
What happens when fopen fails?
When you create a file, the function fopen returns a file pointer. If the attempt to create a file fails for any reason, the function returns false.
Example 2 - create file for reading and writing

The code above creates a new file as does in example one but it creates the file for both reading and writing in the current directory.
The mode "w+" creates a new file for reading and writing, places the pointer in the beginning of the file. If the file already existed, it deletes everything from the file.
Similarly, you can use mode 'a' and 'a+' for creating new files. However with these modes, if the file already exists, it will not truncate the file (i.e. it will not delete any content in the file) and places the pointer at the end of the file for writing.
So, in the tutorial we learned how to create a new file using the php fopen function, next we will learn how to open existing files for reading and writing using the fopen function.