Jump to content

Help with simple mistake...


Foser

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.
Link to comment
https://forums.phpfreaks.com/topic/23154-help-with-simple-mistake/
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.
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
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.....
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
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...

Archived

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

×
×
  • Create New...

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.