The forums have permanently moved to This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 5 of 5

Thread: PHP Mysql counter

  1. #1

    PHP Mysql counter

    Hi, I've got a counter that connects to a database.. But it's not working.. Can somebody please tell me why, or maybe you have another script for it :

    PHP Code:



    $result mysql_query("SELECT * FROM counter WHERE page='$page'",$connnews);


    mysql_num_rows($result)==0)//we don't have a record for it


    else if(

    UPDATE counter SET count=count+1 WHERE page='$page'



    $newResult mysql_query($sql,$connnews);

    print $count+1;


  2. #2
    You're not saying what it's not doing but i'll have a go. I think its:
    Variables in php in between single qoutes are not evaluated to variables.....

    so you'll have to write "'". $page . "'"

  3. #3
    ^wrong. variables in single quotes aren't evaluated to variables unless those single quotes are also wrapped in double quotes. in that case, the single quotes are taken literally and the variable is evaulated. so pucca's syntax is correct.

    my first suggestion is to echo out your variables prior to using them. especially $page prior to your first query.

  4. #4

    Thanks. I got another script now, that IS actually working, on my localhost.. But on the server it doesn't.. How's that possible??

    PHP Code:
    //make a connection
    //store the result of the query in $result
    $result mysql_query("SELECT * FROM counter");
    //retrieve the fields in our table
    $fields mysql_fetch_row($result);
    //update the count field by 1
    mysql_query("UPDATE counter SET count = count+1");
    //$mycount variable is set to the first field (count)
    $mycount $fields[0];
    //display the count
    echo $mycount
    I've got another file pointing to the db_connect.php, so it's not as if my connection is wrong.. Is it maybe something to do with that InnoDB / MyISAM stuff??? Cause, on my db on my localhost, it's MyISAM, and on the remote server, it's the other one? But I doubt it, huh?


  5. #5
    never mind. I just had to insert 1...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Home About Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012