Jump to content

Archived

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

Foser

Help with simple mistake...

Recommended Posts

Hello,


I'm quite new to PHP, but I learn quickly. I did the tutorial on a simpel counter threw mysql and php, with no mistakes.
Although Where can I find the count of people that came, i refreshed teh website, and went with another browser and didn't see any change in my mysql database no valuables changed. Where do I see how much people came?

[code]<?php
session_start();
echo "Hello";
$connection = mysql_connect ("localhost", "root", "*****" );
if (!session_is_registered("counted")){
  mysql_query ("UPDATE simplecount SET count=(count + 1) WHERE count_id=1");
  WHERE count_id=1");
session_register ("counted");
}
?>[/code]

Thanks in advance to anyone which helped.

Share this post


Link to post
Share on other sites
You see where it says if(!session_is_registered("counted"))

That basically means if you haven't already been counted, then count you.  If you have, don't count you.

You would need a clean session to be counted again.  Close your browser entirely and reopen the page, it should count you again.

Share this post


Link to post
Share on other sites
I do realise that.

I have done multiple sessions. But my question is. Where does it count the hits? I've looked eevryone in the database and stuff. but cant seem to find the variable which shows how many people (sessions) that have been recorded.

Share this post


Link to post
Share on other sites
It's updating the [color=red]count[/color] field in the [color=green]simplecount[/color] table.

Also, the following is wrong:
[code]
<?php
mysql_query ("UPDATE simplecount SET count=(count + 1) WHERE count_id=1");
WHERE count_id=1");
?>
[/code]

It should just be as follows:
[code]
<?php
mysql_query ("UPDATE simplecount SET count=(count + 1) WHERE count_id=1");
?>
[/code]

Regards
Huggie

Share this post


Link to post
Share on other sites
OKay, this is what my code looks like now.

[code]<?php
session_start();
echo "Hello";
mysql_connect ("localhost", "root", "445589" );
mysql_select_db("counter01");
if (!session_is_registered("counted")){
  mysql_query ("UPDATE simplecount SET count=(count + 1) WHERE count_id=1");
session_register ("counted");
}
?>[/code]

But now, I still cant see anything in my mysql database that seem sliek it counted something. i quit my browser wen ton page, changed browser and done lodes. But I cant see much that has changed in my database in variables.....

Share this post


Link to post
Share on other sites
Try this:

[code]
<?php
session_start();
echo "Hello";
mysql_connect ("localhost", "root", "445589" );
mysql_select_db("counter01");
if ($_SESSION['counted'] != "true"){
  $result = mysql_query("UPDATE simplecount SET count = (count + 1) WHERE count_id = 1") or die ("Unable to execute query: " . mysql_error());
  $_SESSION['counted'] = $result;
}
?>
[/code]

The result of an update statement in mysql_query() is always either true or false, so why not use that as above.  Also put a bit of error handling in there.

Regards
Huggie

Share this post


Link to post
Share on other sites
Thanks huggie, its working fine no bugs.

Although I still don't know where it's counting i don't see anything in the database. I don't see any variables changing.

Thanks.

Share this post


Link to post
Share on other sites
table : simplecount 
record: 0
Type: InnoDB
collation: latin1_swedish_ci
seize 16 kb



My first row:
Field: count
type: varchar(255)
collation: latin1_swedish_ci
attributes:  ---
Null: No

My Second Row:
Field: count_id
type: varchar(25)

rest is same as first.

its nothing fancy...

Share this post


Link to post
Share on other sites
The table should have two columns and one row...

Column: count_id
Type: int(6)
Value: 1

Column: count
type: int(6)
Value: 0

That should do the trick.

Huggie

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.