Jump to content


Photo

Help with simple mistake...


  • Please log in to reply
9 replies to this topic

#1 Foser

Foser
  • Members
  • PipPipPip
  • Advanced Member
  • 272 posts

Posted 06 October 2006 - 07:08 AM

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?

<?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");
}
?>

Thanks in advance to anyone which helped.

#2 Hi I Am Timbo

Hi I Am Timbo
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 06 October 2006 - 07:13 AM

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.

#3 Foser

Foser
  • Members
  • PipPipPip
  • Advanced Member
  • 272 posts

Posted 06 October 2006 - 08:41 AM

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.

#4 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 06 October 2006 - 08:44 AM

It's updating the count field in the simplecount table.

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

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

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#5 Foser

Foser
  • Members
  • PipPipPip
  • Advanced Member
  • 272 posts

Posted 06 October 2006 - 08:52 AM

OKay, this is what my code looks like now.

<?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");
}
?>

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.....

#6 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 06 October 2006 - 09:30 AM

Try this:

<?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;
}
?>

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
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#7 Foser

Foser
  • Members
  • PipPipPip
  • Advanced Member
  • 272 posts

Posted 06 October 2006 - 09:42 AM

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.

#8 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 06 October 2006 - 10:00 AM

OK, can you provide me the structure of your database then...

Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#9 Foser

Foser
  • Members
  • PipPipPip
  • Advanced Member
  • 272 posts

Posted 06 October 2006 - 01:16 PM

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...

#10 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 06 October 2006 - 01:34 PM

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
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users