Wednesday, 31 October 2007

myToDoListPHP v 0.2

I have released an upgrade of myToDoListPHP.

Now you can sort the tasks order them simply with drag and drop.

In this screenshots the task completed has moved to end:


I am develope new functionalities for MyToDoList PHP integrated also whit myPagePHP.
Stay tuned for news. You can download the full package here.

Read More

Add delicious button with counter in your blogger posts

This is a blogger hack to add a delicious button with a counter which show the number of users that share the current link for each post.

The result is like this:

add to del.icio.us saved by 456 users

  • Update: november 13, 2007
  • I have solved an issue with the delicious counter when more posts are displayed in a single page november 5, 2007
  • I have solved an issue for Internet Explorer 6-7 november 5, 2007
  • If you use Internet Explorer you have a javascript error if current link is not added on del.icio.us. Add it first! november 13, 2007
In your blogger account, select modify HTML and check expand widget models. Find this code:

<p class="post-footer-line post-footer-line-3">


and add this code below:

<a expr:href='"http://del.icio.us/post?url="+ data:post.url + "&amp;title" + data:post.title' target='_blank'>add to del.icio.us</a>
saved by <span class='delsquare' expr:id='"a"+data:post.id'>0</span> users

<script type='text/javascript'>
function displayURL(data) {
var urlinfo = data[0];
if (!urlinfo.total_posts) return;
document.getElementById('a<data:post.id/>').innerHTML = urlinfo.total_posts;
}
</script>
<script expr:src = '"http://badges.del.icio.us/feeds/json/url/data?url= " + data:post.url + "&amp;callback=displayURL"'/>


Add CSS class
Copy this code in the <head> section of template to format the number of users that share the current link:

<style>
.delsquare{

font-family:
Arial;
background:#0033CC;
padding:2px 4px;
font-weight:bold;
font-size:12px;
color:#FFFFFF;
}
</style>



Add a retweet counter on your website with ReTweet.comAdd a retweet counter on your posts with TweetmemeHow to install Disqus comments into BloggerImprove the default comment system with Google Friend ConnectAdd TwitThis on your Blogger templateAdd Digg vote button on Blogger Template (update)Add delicious button with counter in your blogger postsPlace Google AdSense below post's title on BloggerAdd StumbleUpon button in your Blogger postsAdd reddit button with counter in your Blogger template Add Technorati blog reaction on your Blogger templateAdd Mixx button on Blogger templateAdd DZone button on Blogger templateAdd Design Float button on Blogger templateSome Blogger Tips you probably don't knowAdd Yahoo! Buzz button on Blogger Template

Read More

Tuesday, 30 October 2007

Split an input text using javascript

This tutorial explains how to split an input text using a javascript function that finds space char between two words and splits them into substring while you type.

Splitted string appears inside a layer below the input text.



Download this tutorial


Step 1: The HTML Code
We have need just an input field and a div layer:

<input name="tag" type="text" id="tag" size="30" onKeyUp="javascript:getTag();" autocomplete="off"/>
<div id="splitResponse"></div>



Step 2: The Javascript function
This is the function that split the texi in input inside the html input element named "tag":


<script language="javascript">
function getTag(){
newTagArray = new Array();
// input field
tagInput = document.getElementById('tag');
totalChar = tagInput.value.length;
// layer for the split response
destLayer = document.getElementById('splitResponse');
destLayer.innerHTML='';
// optional: format the input field in lower case
tagString = tagInput.value.toLowerCase();
// find the space position between two words
position = tagString.indexOf(' ');
i = 0;
while(position>=) {
tagStringN = tagString.substring(0, position);
newTagArray[i] = '<a href="#">'+tagStringN+'</a> ';
tagString = tagString.substring(position+1, totalChar);
position = tagString.indexOf(' ');
// Create a new <span> element to append inside the layer splitResponse
var element = document.createElement('span');
element.innerHTML = newTagArray[i];
destLayer.appendChild(element);
i=i++;
}
}
</script>


Download this tutorial

Read More

Monday, 29 October 2007

Twitter: send message from a PHP page using Twitter API

Are you a Twitter addicted? This post illustrates how to post a message from a custom PHP page using the Twitter API

This is a very simple tutorial (really just some line of code!) that explains how to post a message using Twitter API from a PHP page.



The tutorial includes a folder called twitter with two PHP file:
  1. 1. insertTwitterMsg.php (it's the application interface)
  2. 2. twitterAPI.php (it's the Twitter API with some changes)

Download original script

Download improved script by Scott Sloan Updated January 08, 2008


Original script: what you have to modify?
The script is ready to use but first, in the file insertTwitterMsg.php you have to modify only two parameters: $twitter_username, with your Twitter username and $twitter_psw, with your Twitter password.

<?php
/* ---------------------------------------- */
// Change these parameters with your Twitter
// user name and Twitter password.
/* ---------------------------------------- */
$twitter_username ='yourTwitterUserName';
$twitter_psw ='yourTwitterPassword';
/* ---------------------------------------- */

/* Don't change the code belove
/* ---------------------------------------- */
require('twitterAPI.php');
if(isset($_POST['twitter_msg'])){
$twitter_message=$_POST['twitter_msg'];
if(strlen($twitter_message)<1){ $error=1; } else { $twitter_status=postToTwitter($twitter_username, $twitter_psw, $twitter_message); } }
/* ---------------------------------------- */
?>


Don't touch the rest of the code!

In insertTwitterMsg.php you have a form that you can reuse in your web projects:


<!-- Send message to Twitter -->
<?php
if(isset($_POST['twitter_msg']) && !isset($error)){?>
<div class="msg"><?php echo $twitter_status ?></div>
<?php } else if(isset($error)){?>
<div class="msg">Error: please insert a message!</div>
<?php }?>
<p><strong>What are you doing?</strong></p>
<form action="insertTwitterMsg.php" method="post">
<input name="twitter_msg" type="text" id="twitter_msg" size="40" maxlength="140"/>
<input type="submit" name="button" id="button" value="post" />
</form>


Save the folder with the tutorial in your localhost, remember to set the correct parameters and launch insertTwitterMsg.php with your browser. Now, you are ready to post messages on Twitter from your PHP page :)

For other info about the modified script provided by Scott Sloan, take a look here


Related posts
- Simple PHP Twitter Search ready to use in your web projects
- Super simple way to work with Twitter API (PHP + CSS)
- Send messages from a PHP page using Twitter API

Read More

How to change a text using javascript

Are you a JavaScript newbie? Do you need to change the code contained within an HTML element?

The solution is very simple. We have to use the javascript method:

getElementbyId()


...that get an element property (for example, value, style, ecc...) by the element ID (for example <div id="myLayer">) and:

.innerHTML="a piece of html code";


... that rewrite the layer content with the HTML code specified. A typical syntax is:

document.getElementById('myLayer').innerHTML ='<strong>Hello World!</strong>';


This code (you have to add it inside a javascript function to work!), change the content of an html element with ID "myLayer" (for example a DIV, H1, H2, SPAN, A...), with <strong>Hello World!>


Download this tutorial



Example 1: A simple text change javascript function

<script language="javascript">
function changeTextSimple(idElement){
document.getElementById.('element'+idElement).innerHTML ='<strong>Hello World</strong>';
}</script>


Example 2: change the text of a <li> element inside an <ul> element
changeText() is a simple function that change the content of a <li> element:

<script language="javascript">
function changeText(idElement){
if(idElement==1){
document.getElementById('element'+idElement).innerHTML ='<a href="http://www.google.com">Google</a>';
} else if(idElement==2){
document.getElementById('element'+idElement).innerHTML ='<a href="http://woork.blogspot.com">Woork</a>';
}
}
</script>

<ul>
<li id="element1">Google</li>
<li id="element2">Woork</li>
</ul>
<a href="#" onClick="javascript:changeText(1)">Change Google into a link</a><br/>
<a href="#" onClick="javascript:changeText(2)">Change Woork into a link</a><br/>


Frequent Errors
When you pass a variable to a Javascript function from an HTML page remember this:

If the parameter is a number the syntax is:
<a href="#" onClick="javascript:changeText(1)">change</a>


else if the parameter is a string the syntax is:
<a href="#" onClick="javascript:changeText('element1')">change</a>

With quote (') around the element name.

Read More

Sunday, 28 October 2007

myPagePhp alpha preview

These are two screenshots of myPagePhp a web application that I am writing with PHP, MySQL and Ajax functionalities.

myPagePhp is an open source project that you you will be able to download and install on your server to manage your web 2.0 social identity on-line. The application contains:
  1. - info about your digital life and your social identity on web (digg, technorati, myspace...)
  2. - Twitter messages directly from the page
  3. - a flickr badge to show your recent photos
  4. - a feed parser, to show your recent post into the page
  5. - a simple to-do list with ajax functionalities (powered by myToDoListPhp)
  6. - del.icio.us integration
... and more functions actually in development.

This is the first screenshot:


This is the second screenshot:


Subscribe my feed and stay tuned for more info about myPagePhp :))

Read More

Saturday, 27 October 2007

My to-do List application update

MyToDoList now use Scriptaculous to add advanced effect to its features

I have updated My to-do list application with Scriptaculous Highlight effect. Now you can also add a note for each post. This is the application's screenshot:


For more info about My to do list, pleas read this post.

Read More

Friday, 26 October 2007

Ajax: add a new element into a list using javascript insertBefore()

This tutorial is a very simple javascript function that add an element <li> into a list <ul> without reload the page. The element is passed from a input text field and is added on top of the list using insertBefore() javascript function.

Download this tutorial


Step 1: HTML code
First, we prepare the HTML code for our page:
  • <input> text field (with id="newElement") for add new element.
  • <ul id="myList"> the list into we will add new elements.
  • <div id="msg"></div> a layer that will show a message if the add action has been completed, or an error if the input field is emty.
Copy and paste this code into the <body> tag:

<style>
body{font-family:'Lucida Grande', Verdana, sans-serif; font-size:14px; color:#666666;}
a:link, a:visited{color:#0033CC;}
h3{border-bottom: solid 2px #DEDEDE; padding:6px 0; color:#000000;}
#msg{background:#FFFFCC; margin:10px; padding:4px; display:none;}
</style>

<h3>Add a new element into a <ul> list</h3>
Add a new element into the list (press "submit" button)<br><br>
<input name="newElement" id="newElement" type="text" value=""/>
<input type="button" value="submit" name="submit" onClick = "javascript:addElement()"/>

<div id="msg"></div>

<ul id="myList">
</ul>


Step 2: the javascript function addElement()
This is the javascript function that use insertBefore() to add the new element on top of the list.In the previous code, to te step 1, add this <script> between <h3>Add a new element into a <ul> list</h3> ... and ... </style> line.

<script language="javascript">
function addElement(){
// Get the value into the input text field
var element=document.getElementById('newElement').value;
if(element==""){
// Show an error message if the field is blank;
document.getElementById('msg').style.display="block";
document.getElementById('msg').innerHTML = "Error! Insert a description for the element";
}else{
// This is the <ul id="myList"> element that will contains the new elements
var container = document.getElementById('myList');
// Create a new <li> element for to insert inside <ul id="myList">
var new_element = document.createElement('li');
new_element.innerHTML = element;
container.insertBefore(new_element, container.firstChild);
// Show a message if the element has been added;
document.getElementById('msg').style.display="block";
document.getElementById('msg').innerHTML = "Elemend added!";
// Clean input field
document..getElementById('newElement').value="";
}
}
</script>


Save and try it!

Read More

Thursday, 25 October 2007

MyToDoList PHP: an open source to-do list written in PHP and AJAX

myToDoListPHP is a simple To-Do list that I am developing using PHP, MySQL and Ajax adding continuous improvements. You can add/delete tasks, and mark a task completed. You can also reuse the code in your projects to simplify your work.

Update history Update november 16, 2007
  • scriptacuolus effects and notes added october 27, 2007
  • sortable task with drag and drop added october 30, 2007
  • ajax search engine added november 1, 2007
  • update to version 0.3 november 11, 2007
  • update to ver 0.3a: I have solved some issues and added a filter for completed task november 14, 2007
  • update to version 0.4 november 15, 2007
  • update to version 0.5, added set task prioriy and % of completion november 16, 2007

Code Update
Download the new code here

Max Pozdeev MyTinyTodoList Website
MyTinyTodoList Demo




This is some application's screenshots:

Add users, tasks and notes:


The search engine, find task and user while you type:



Content
The package is composed from these files:
  • 1. todolist.php (the application's page)
  • 2. ajax_framework.js (javascript functions for Ajax functionalities)
  • 3. dbconnection.php (contains mySQL parameters for the connection to database. You have to change the default values with your parameters.)
  • 4. insertTask.php (insert a new task)
  • 5 deleteTask.php (delete a task)
  • 6 completeTask.php (mark a task complete)
  • 7. createDBtable.php (you can use this file to create automatically the database table)
  • 8. Scriptaculous folder (enable scriptaculous effects) october 27, 2007
  • 9. saveNote.php (you can add a note for each task) october 27, 2007
  • 10. in-showTask.php (code optimization) november 1, 2007
  • 11. insertUser.php (add a new user) november 11, 2007
  • 12. in-userRow.php (code optimization) november 11, 2007
  • 13. in-lineBar.php (code optimization) november 14, 2007
  • 14. in-sqlProperties.php (enable filter for completed tasks using an SQL parameter) november 14, 2007
  • 14. in-hideCompleteTask.php (save preference show/hide completed tasks into database) november 14, 2007
  • 15. in-modifyTask.php (modify task interface) november 15, 2007
  • 16. modifyTask.php (update task) november 15, 2007

Step 1: create a new MySQL database using myAdminPhp
First step, you have to create a new MySQL database using myAdminPHP and modify the connection's parameters ($db_host, $db_name, $username, $password) into the file dbconnection.php in this way:


<?php
// REQUIRED! Parameters to connecto to your DB
// CHANGE ONLY $db_host, $db_name, $username, $password
$db_host="localhost";
$db_name="woork";
$username="root";
$password="root";

// DON'T CHANGE THE REST!
$db_con=mysql_connect($db_host,$username,$password);
$connection_string=mysql_select_db($db_name);
mysql_connect($db_host,$username,$password);
mysql_select_db($db_name);
?>


Step 2: create the database table using createDBtable.php
Now you can open createDBtable.php using your web browser in your localhost. This file will create a table TODOLIST to store the application's data. Verify on phpMyAdmin that the table has been created.

Step 3: run the application!
Open todolist.php with you browser and try the application!
You can reuse, modify, improve and distribute the code. For info please contact me.

Read More

Wednesday, 24 October 2007

Parsing Feed RSS to HTML using MagpieRSS and PHP

This simple tutorial explains how to parse a feed rss to HTML using MagpieRSS and some line of PHP code. MagpieRSS is an XML-based RSS parser in PHP and is included in the download file, into the folder parser.

Download this tutorial


The basic code
Create a new file index.php and copu and paste the following code into the <body> tag. This code parse the feed associated to $url variable in HTML and show in a list (<li> HTML tag) into a PHP page, the links to all items in the feed. In the first line of PHP code, you have to use require_once() to include rss_fetch.inc MagpieRSS file.

<? php
require_once('parser/rss_fetch.inc');
$url = 'http://feeds.feedburner.com/Woork';
$rss = fetch_rss( $url );
echo "Title: " . $rss->channel['title'];
echo "<ul>";
foreach ($rss->items as $item) {
echo "<li>". "<a href=\"". $item['link'] ."\">". $item['title'] ."</a></li>";
}
echo "</ul>";
?>


Limit the number of links to show in HTML
To limit the number of links that you can show in the page you can use a variable $count and a if statement:


<? php
require_once('parser/rss_fetch.inc');
$url = 'http://feeds.feedburner.com/Woork';
$rss = fetch_rss( $url );
echo "Title: " . $rss->channel['title'];
echo "<ul>";
// Limit at only 10 links
$count=1;
foreach ($rss->items as $item) {
echo "<li>". "<a href=\"". $item['link'] ."\">". $item['title'] ."</a></li>";
$count ++;
if($count==10){ break;}
}
echo "</ul>";
?>


Dowload the tutorial and try it!

Read More

Change the layer background color using a simple Javascript functions

These are two simple javascript functions that change on fly the background color of a layer without reload the page. To change the CSS background color with javascript we will use:

document.getElementById('ID').style.background ='background color'

Download this tutorial


1. Change background color
Copy and paste this code into <body> tag:

<script language="javascript">
function changeBg(idLayer){
idLayer_n = document.getElementById(idLayer);
if(idLayer_n.style.background!=''){
document.getElementById(idLayer).style.background ='#dedede';
document.getElementById('cb_text').innerHTML ='Changed! Click to restore';
} else {
document.getElementById(idLayer).style.background ='';
document.getElementById('cb_text').innerHTML ='Change Background color';
}
}
</script>

<div id='myLayer'>The script change the background color fo this layer!</div>
<a href="#" onclick="javascript:changeBg('myLayer')" id="cb_text">Change Background color</a>


2. Change background and text color with input field
This script change the layer background and text color using two input field to select the colors (esadecimal value).

To get the input field value with a javascript function we have to use:

document.getElementById('id').value;


Copy and paste this code into <body> tag:

<script language="javascript">
function changeBgInput(idLayer){
idLayer_n = document.getElementById(idLayer);
idColor_txt = document.getElementById('myColor_txt').value;
idColor_bg = document.getElementById('myColor_bg').value;
idLayer_n.style.color = idColor_txt;
idLayer_n.style.background = idColor_bg;
</script>

Text color: <br/>
<input type="text" id="myColor_txt" name="myColor_txt" value="#FFFFFF"><br/>
Background color: <br/>
<input type="text" id="myColor_bg" name="myColor_bg" value="#555555"><br/>
<a href="#" onClick="javascript:changeBgInput('myLayer');">Change text and background color</a>

Read More

Tuesday, 23 October 2007

Magnify text using Javascript

This is a simple javascript function that magnifies a text's size on fly, without reload the page.

The script use javascript to modify the CSS attribute, font-size that in javascript is rewritten with fontSize.
The script magnify the text until a max dimension set to 40px.

Download this script


The page code
Copy and past this code into the tag <body>;

<style type="text/css">
body{font-size:13px;}
</style>

<script language="javascript">
// Set the actual size to 13px equal to the value of font-size attribute
// on body CSS tag redefinition;
actualSize=13;
function magnifyText(idText){
// Increment of 10%
incrementSize=actualSize*(1.1);
// set a maximum size to expand text: for example 40 px;
if(incrementSize<40){
document.getElementById(idText).style.fontSize =incrementSize+'px';
actualSize=incrementSize;
}
}
</script>

<div id="myText">This is an example to magnify text size on fly.</div><br />
<a href="#" onclick="javascript:magnifyText('myText')">magnify</a>

Read More

Insert record into database using Ajax and Coldfusion

In the previous lesson we have seen how to use Ajax to insert a record into a database table using PHP. In this lesson we will explain how to implement the same tutorial using Coldfusion instead of PHP.

Download tutorial

How it works?
The structure is the same of the previous post. We have:
  1. index.cfm (contains a simple form with an input text)
  2. ajax_framework.js (the javascript function to enable ajax functionalities)
  3. insert.cfm (the Coldfusion code to save the record into a database table)

We have seen how that index.cfm and ajax_framework.js are indipendent from the script language (PHP, ASP, Coldfusion...).

Step 1: index.cfm
This is the code for index.cfm: a simple form that calls (in the action attribute) a javascript function, insertRecord(), in ajax_framework.js.

<!-- Include AJAX Framework -->
<script src="ajax/ajax_framework.js" language="javascript"></script>

<!-- Show Message for AJAX response -->
<div id="insert_response"></div>

<!-- Form: the action="javascript:insert()"calls the javascript function "insert" into ajax_framework.js -->
<form action="javascript:insert()" method="post">
<input name="site_url" type="text" id="site_url" value=""/>
<input name="site_name" type="text" id="site_name" value=""/>
<input type="submit" name="Submit" value="Insert"/>
</form>


How you can see, nothing is changed respect to index.php of the previous post.

Step 2: the javascript function insert() in ajax_framework.js

In this lesson we have see how enable the XMLHTTPRequest. In ajax_framework.js file we have added this code:

/* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */
function createObject() {
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_type = new XMLHttpRequest();
}
return request_type;
}

var http = createObject();


Now, in the same javascript file, we will add other lines of code for the function insert():

/* -------------------------- */
/* INSERT */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
var nocache = 0;
function insert() {
// Optional: Show a waiting message in the layer with ID login_response
document.getElementById('insert_response').innerHTML = "Just a second..."
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
var site_url= encodeURI(document.getElementById('site_url').value);
var site_name = encodeURI(document.getElementById('site_name').value);
// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http.open('get', 'insert.cfm?site_url='+site_url+'&site_name=' +site_name+'&nocache = '+nocache);
http.onreadystatechange = insertReply;
http.send(null);
}
function insertReply() {
if(http.readyState == 4){
var response = http.responseText;
// else if login is ok show a message: "Site added+ site URL".
document.getElementById('insert_response').innerHTML = 'Site added:'+response;
}
}


How you can see, the only change, respect to insert() function of the previous tutorial is:

http.open('get', 'insert.cfm?site_url='+site_url+'&site_name=' +site_name+'&nocache = '+nocache);


...instead of:

http.open('get', 'insert.php?site_url='+site_url+'&site_name=' +site_name+'&nocache = '+nocache);


Step 3: insert.cfm


<cfif isDefined('URL.site_url') AND isDefined('URL.site_name')>
<cfset site_url= #URL.site_url#gt;
<cfset site_name= #URL.site_name#gt;
<!--- Change myDatasourceName with your datasource --->
<cfquery datasource="myDatasourceName">
INSERT INTO SITE (site_url, site_name) VALUES (
"#site_url#",
"#site_name#"
</cfquery>
<!--- Show the site name for the ajax response --->
<cfoutput>#site_name#</cfoutput>
<cfelse>
Error! Please fill all fields!
</cfif>


Save alla and try it in your localhost server.

Read More

Monday, 22 October 2007

Insert record into database using Ajax and PHP

This lesson will explains how to insert a record into a database table and show a message after insertion. In this example we will add a web site (URL and site name) into a table.

How does it works?
In the site root we have these files:
  1. index.php (contains a simple form with an input text)
  2. ajax_framework.js (the javascript function to enable ajax functionalities)
  3. insert.php (the PHP code to save the record into a database table)

Take a mind that index.php and ajax_framework.js are indipendent from the script language (PHP, ASP, Coldfusion...). For example index.php can be adopted also if you are using another script language changed only the extension (ex. from .php to .cfm if you use Coldfusion) without change the code.

Step 1: index.php
This is the code for index.php: a simple form that calls (in the action attribute) a javascript function, insertRecord(), in ajax_framework.js.

<!-- Include AJAX Framework -->
<script src="ajax/ajax_framework.js" language="javascript"></script>

<!-- Show Message for AJAX response -->
<div id="insert_response"></div>

<!-- Form: the action="javascript:insert()"calls the javascript function "insert" into ajax_framework.js -->
<form action="javascript:insert()" method="post">
<input name="site_url" type="text" id="site_url" value=""/>
<input name="site_name" type="text" id="site_name" value=""/>
<input type="submit" name="Submit" value="Insert"/>
</form>


Step 2: the javascript function insert() in ajax_framework.js

In this lesson we have see how enable the XMLHTTPRequest. In ajax_framework.js file we have added this code:

/* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */
function createObject() {
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_type = new XMLHttpRequest();
}
return request_type;
}

var http = createObject();


Now, in the same javascript file, we will add other lines of code for the function insert():

/* -------------------------- */
/* INSERT */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
var nocache = 0;
function insert() {
// Optional: Show a waiting message in the layer with ID login_response
document.getElementById('insert_response').innerHTML = "Just a second..."
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
var site_url= encodeURI(document.getElementById('site_url').value);
var site_name = encodeURI(document.getElementById('site_name').value);
// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http.open('get', 'insert.php?site_url='+site_url+'&site_name=' +site_name+'&nocache = '+nocache);
http.onreadystatechange = insertReply;
http.send(null);
}
function insertReply() {
if(http.readyState == 4){
var response = http.responseText;
// else if login is ok show a message: "Site added+ site URL".
document.getElementById('insert_response').innerHTML = 'Site added:'+response;
}
}


Step 3: insert.php
This is the insert.php page code:

<!-- Include Database connections info. -->
<?php include('config.php'); ?>

<!-- Verify if user exists for login -->
<?php
if(isset($_GET['site_url']) && isset($_GET['site_name'])){

$url= $_GET['site_url'];
$sitename= $_GET['site_name'];

$insertSite_sql = 'INSERT INTO SITE (site_url, site_name) VALUES('. $url. ',' . $sitename. ')';
$insertSite= mysql_query($insertSite_sql) or die(mysql_error());

<!-- If is set URL variables and insert is ok, show the site name -->
echo $sitename;
} else {
echo 'Error! Please fill all fileds!';
}
>


Save all, and try it in your localhost!

Read More