post data on load

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ed209
Forum Contributor
Posts: 153
Joined: Thu May 12, 2005 5:06 am
Location: UK

post data on load

Post by ed209 »

Hi,

I have some static html pages that I want to keep the number of views they receive.

All I need to do is pass back the ID of the page which will be written into the page when it is saved.

At the moment I have an onload event in the body tag that calls the following javascript:

Code: Select all

function sendData(advert_id){
		var url="my_db_update_file.php?pv=" + advert_id;
	       window.open(url, "_self");		
	}
and the PHP page that I'm posting back to looks like this:

Code: Select all

<?php

	class dbConnect{
		/**/
		var $server="localhost";
		var $user="user";
		var $password="password";
		var $database="database";
	}
	$dbclass = new dbConnect;
	
	mysql_connect($dbclass->server,$dbclass->user,$dbclass->password);
	mysql_select_db($dbclass->database);
	
	// update the stats
	$add = mysql_query('INSERT INTO `test` (`id`,`passed_val`) VALUES ("","'.$_GET['pv'].'")');
	
	mysql_close();
	

?>
The trouble is, I think the javascript is reloading the page with a blank one. Is it possible to load an html page and execute a php page and passing it some variables? (without loosing / reloading the current html page)

Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

What about using the Javascript detection thing I posted a while back?

viewtopic.php?t=42557
Post Reply