190319m9 Posted December 27, 2008 Share Posted December 27, 2008 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 More sharing options...
clonetrooper9494 Posted December 27, 2008 Share Posted December 27, 2008 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 More sharing options...
190319m9 Posted December 27, 2008 Author Share Posted December 27, 2008 But I think changing ($y) to "$y" will render it as a string variable. Or may be we should find out a way of printing value of $y instead of using ($y) or "$y". Link to comment Share on other sites More sharing options...
clonetrooper9494 Posted December 27, 2008 Share Posted December 27, 2008 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 More sharing options...
jeffman Posted December 27, 2008 Share Posted December 27, 2008 How to replace ???????????????????? with values carried by cookie?$hit = isset($_COOKIE['hit']) ? $_COOKIE['hit'] : 0; Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.