Jump to content

Carrying And Retrieving Variable Using Cookie.


190319m9

Recommended Posts

Initial Page Code

<?php $con=mysql_connect("localhost", "root", "discreet");		if (!$con)			{			die ('Error : ' . mysql_error());			}		mysql_select_db("hitcounter", $con);		$initial_value = mysql_query("SELECT * FROM test_hit_counter");		while ($carried = mysql_fetch_array($initial_value))		{		$y = $carried['hits'] + 1;		} 		mysql_close($con);		setcookie("hit", ($y));				?>

Is this code for generating a cookie is OK? Final Page Code

<?php    $con=mysql_connect("localhost", "root", "discreet");        if (!$con)            {            die ('Error : ' . mysql_error());            }        mysql_select_db("hitcounter", $con);        mysql_query("UPDATE test_hit_counter SET hits = ????????????????????????????");    ?>

How to replace ???????????????????? with values carried by cookie?

Link to comment
Share on other sites

http://w3schools.com/php/php_cookies.aspCheck and make sure that your are using the functions correctly, if it still doesn't work, then post in this topic again with the new code.One problem, setcookie("hit", ($y)); , you need to state when it will expire and change ($y) to "$y"
Link to comment
Share on other sites

hmmm... let me try out a couple of things

<?php$var1 = "23" + 5;echo $var1;echo "<br><br>";$var2 = 23 + 5;echo $var2;echo "<br><br>";$var3 = "23" . 5;echo $var3;echo "<br><br>";$var4 = "23" + "5";echo $var4;echo "<br><br>";?>

outputs this:

282823528

It won't matter if its a string or not, cuz as long as you use + sign, it will work

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...