Jump to content

hits counter


Go to solution Solved by cyberRobot,

Recommended Posts

Hey guys,

 

I have been trying to figure out what is wrong with my unique hit counter on my site.

 

With a lot of trouble shooting i have figured out that the function to add the ip to the table is not working. Can anyone help me out?

function ip_add($i){
global $con;
global $realid;

$query_run=mysqli_query($con,"INSERT INTO media(ip) VALUES ('$i') WHERE id=".$realid);
}
Link to comment
https://forums.phpfreaks.com/topic/297476-hits-counter/
Share on other sites

$i is just supposed to be a placeholder for when i actually run the function and $realid is a value taken from the url.

That's nice. But the error happens when the function actually runs, so what are the values of those two variables when the function actually runs?

 

I'm not quite sure how i would be able to use the mysqli_error() function. I'm a newb :s

Did you click the link I posted?
Link to comment
https://forums.phpfreaks.com/topic/297476-hits-counter/#findComment-1517399
Share on other sites

$user_ip =$_SERVER['REMOTE_ADDR'];

ip_add($user_ip);

and $realid is a number that corresponds to the id collum in my table

$url=$_SERVER['REQUEST_URI'];
$realid=trim(strstr($url, '.'),'.');

and yeah i clicked on the link but i still dont understand...

 

 

if (!mysqli_query($query_run, "SET ip=1")) {
    printf("Errormessage: %s\n", mysqli_error($query_run));
}

that gives me a bunch of errors.

 

Edited by BlueM
Link to comment
https://forums.phpfreaks.com/topic/297476-hits-counter/#findComment-1517401
Share on other sites

and $realid is a number that corresponds to the id collum in my table

$url=$_SERVER['REQUEST_URI'];
$realid=trim(strstr($url, '.'),'.');

 

There is nothing in that which says $realid is a number.

 

I'm trying to get actual. values. of. those. variables. Not a description of what you think they are. Not code showing how they get values. Actual. Values.

 

Change your function to look like

function ip_add($i){
global $con;
global $realid;

$query="INSERT INTO media(ip) VALUES ('$i') WHERE id=".$realid;
echo "THE QUERY IS '$query'";
$query_run=mysqli_query($con,$query);
}
Run your script. What is the entire message that it outputs? I'd like you to try to provide the entire message from that echo. Yes, I know what the first three words will be, but that's not the point.

 

 

if (!mysqli_query($query_run, "SET ip=1")) {
    printf("Errormessage: %s\n", mysqli_error($query_run));
}
that gives me a bunch of errors.

 

You've now demonstrated that you do, in fact, understand how to use the function. Or at least came upon some combination of letters and symbols that together formed valid code which also happened to demonstrate how mysqli_error() is used.

 

Now, I have no idea what this new bit of code has to do with anything you've posted so far. Maybe it's supposed to work the same way as an INSERT query? But if you want to resolve those errors then your next step should be to post what those errors are. Again, the actual errors. Not a description of what they say. The actual messages you are seeing.

Edited by requinix
Link to comment
https://forums.phpfreaks.com/topic/297476-hits-counter/#findComment-1517402
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.