Jump to content

Help with PHP class for creating mysql table, hit counter, displaying the result?


Recommended Posts

HitCounter.php

CountVisits2.php

 

I'm struggling with this assignment, I'm not sure what I'm doing wrong!  If somebody could please point out what my errors are that would be great.  I attached the two files I'm using above; below are the directions for the assignment:  this is the error I get "[03-Apr-2014 21:10:56 America/Denver] PHP Fatal error:  Call to undefined function my_sql_fetch_row() in /project5/HitCounter.php on line 78"

 

 

"For this project, you will create a HitCounter class that counts the number of hits to a Web page and stores the results in a MySQL database.  Use a private data member to store the number of hits and include public set and get member functions to access the private counter member variable.  Note, you must develop 2 php files for this project.  The first is a class called HitCounter.php and the second is a file called CountVisits.php

 

The CountVisits file will be the one used by the user and it will instantiate an instance of the HitCounter class.  The HitCounter class takes care of opening the database file and table and obtaining the current number of hits, placing that number in a private variable. 

 

That private variable is accessible in the object by calling the "get" function.  Before terminating, the CountVisits program has to set the new value using the "set" function (in the class definition, the "set" function should increment the current counter by one and update the database).  Note that part of the constructor function in HitCounter.php should be to check to see if your table exists and then create it, if it does not, and initialize the table with values."

Edited by bernardSP

your assignment isn't even relevant to the error message. did you look at the error and the line of code where the error is at and TRY to determine why the function name you used in your code isn't defined? you have a spelling/naming error in the function name you typed in your code.

 

two three serious issues with this code -

 

1) DO NOT use the @ error suppressor, ever. it's bad programming practice. if you are getting errors with any statements, you will need to find what is causing those errors and fix the problem. hiding the errors won't fix what is causing them and without the error messages, you won't even know where to start looking to find out why our code isn't working.

 

2) the mysql_ database functions are DEPRECIATED and will be eliminated in a future php version. you should NOT be learning the mysql_ functions at this point in time. see this link - http://www.php.net/manual/en/mysqlinfo.api.choosing.php

 

3) DO NOT nest function calls when the inner function can fail due to an error, i.e. the line in question that is producing your current error - my_sql_fetch_row(@mysql_query($q)); when you do this, you cannot test for errors, handle them, and prevent follow-on errors in the outer function calls.

Edited by mac_gyver
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.