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
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.
Link to comment
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
Link to comment
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.....
Link to comment
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
Link to comment
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...
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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