Hello, I am trying two days now and I have spent about 12+ hours on this and I can't find a solution :( Please help, or I am gonna lose my mind!
I am trying to save user's monitor resolution on MySQL. I almost done it but, I have a problem with page reloads... I set a cookie that contains users resolution and I am trying to read it with php and then write it to MySQL, because javascript can't write to MySQL. The cookie is set OK, but php read it after a reload. Reload creates ton's of problem to other part's of web page, so can anyone please help me do exactly what I am doing without reload?
Here is my code:
<html>
<head>
<script type="text/javascript">
//setting cookie
function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}
setCookie('res',screen.width+"x"+screen.height,365);
//cookie set
</script>
<?php
echo $screen_res = $_COOKIE["res"]; //here is the problem, this is null on first load
//I have to reload the page to get this work
//now connecting to mysql to write data
$dbhost = 'localhost';
$dbuser = 'username';
$dbname = 'test';
$dbpasswd = 'password';
$con = mysql_connect($dbhost, $dbuser, $dbpasswd);
unset($dbpasswd);
mysql_select_db("test", $con);
$sql = "CREATE TABLE test_table
(
Screen_res varchar(10)
)";
mysql_query($sql,$con);
mysql_query("INSERT INTO test_table (Screen_res)
VALUES ('$screen_res')");
mysql_close($con);
//data written
?>
</head>
<body onload="checkCookie()"> //<!-- I don't know what this does, but if I remove script brokes -->
</body>
</html>
Aslo, sorry for my bad english...