Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8394509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:04:50+00:00 2026-06-09T20:04:50+00:00

I have made some statistics which I want to insert into database to see

  • 0

I have made some statistics which I want to insert into database to see traffic stats.
I mostly have HTML pages so I used POST method to get statistics posted by a PHP file, but it is not working no stats are inserted into database table.

HTML Codes

    <form action="_global/stats/stats.php" method="post">
    <input type="hidden" name="stats" value="true" />
    </form>

PHP Codes

        if (isset($_POST['stats']))
    {
    $stats = $_POST['stats'];
    }
    else
    {$stats="false";}

    if ($stats == "true"){ 

        if(!empty($_SERVER['REQUEST_URI'])){
        $url = $_SERVER['REQUEST_URI'];
        }else{$url = "";}

        if(!empty($_SERVER['REMOTE_ADDR'])){
        $user_ip = $_SERVER['REMOTE_ADDR'];
        }else{$user_ip = "";}

        if(!empty($_SERVER['REMOTE_PORT'])){
        $user_port = $_SERVER['REMOTE_PORT'];
        }else{$user_port = "";}

        if(!empty($_SERVER['SERVER_ADDR'])){
        $server_ip = $_SERVER['SERVER_ADDR'];
        }else{$server_ip = "";}

        if(!empty($_SERVER['SERVER_PORT'])){
        $server_port = $_SERVER['SERVER_PORT'];
        }else{$server_port = "";}

        if(!empty($_SERVER['REQUEST_METHOD'])){
        $request_type = mysql_real_escape_string ($_SERVER['REQUEST_METHOD']);
        }else{$request_type = "";}

        if(!empty($_SERVER['HTTP_USER_AGENT'])){
        $browser_type =  mysql_real_escape_string ($_SERVER['HTTP_USER_AGENT']);
        }else{$browser_type = "";} 

    mysql_query("INSERT INTO jinendra_statistics.statistics SET url='$url', user_ip='$user_ip', user_port='$user_port', server_ip='$server_ip', server_port='$server_port', request_type='$request_type', browser_type='$browser_type' ");

    }

Please See what’s going wrong here and suggest any possible way to do it.

Update

PHP file with these codes is working i get values in database. but using it with HTML doesn’t insert values in database.

        if(!empty($_SERVER['REQUEST_URI'])){
    $url = $_SERVER['REQUEST_URI'];
    }else{$url = "";}

    if(!empty($_SERVER['REMOTE_ADDR'])){
    $user_ip = $_SERVER['REMOTE_ADDR'];
    }else{$user_ip = "";}

    if(!empty($_SERVER['REMOTE_PORT'])){
    $user_port = $_SERVER['REMOTE_PORT'];
    }else{$user_port = "";}

    if(!empty($_SERVER['SERVER_ADDR'])){
    $server_ip = $_SERVER['SERVER_ADDR'];
    }else{$server_ip = "";}

    if(!empty($_SERVER['SERVER_PORT'])){
    $server_port = $_SERVER['SERVER_PORT'];
    }else{$server_port = "";}

    if(!empty($_SERVER['REQUEST_METHOD'])){
    $request_type = mysql_real_escape_string ($_SERVER['REQUEST_METHOD']);
    }else{$request_type = "";}

    if(!empty($_SERVER['HTTP_USER_AGENT'])){
    $browser_type =  mysql_real_escape_string ($_SERVER['HTTP_USER_AGENT']);
    }else{$browser_type = "";} 

    mysql_query("INSERT INTO jinendra_statistics.statistics SET url='$url', user_ip='$user_ip', user_port='$user_port', server_ip='$server_ip', server_port='$server_port', request_type='$request_type', browser_type='$browser_type' ");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:04:51+00:00Added an answer on June 9, 2026 at 8:04 pm

    To anyone reading this: There were two issues that were fixed.

    1) The query had incorrect syntax, and

    2) The process of submitting the form was also incorrect.


    mysql_query("INSERT INTO jinendra_statistics.statistics (url, user_ip, user_port, server_ip, server_port, request_type, browser_type) VALUES ('$url', '$user_ip', '$user_port', '$server_ip', '$server_port', '$request_type', '$browser_type')";
    

    You want to use SET for UPDATE and the syntax I provided for INSERT.


    this/page.php

    <?php
    
    if(isset($_POST['stats'])){
    
     if(!empty($_SERVER['REQUEST_URI'])){
    $url = $_SERVER['REQUEST_URI'];
    }else{$url = "";}
    
    if(!empty($_SERVER['REMOTE_ADDR'])){
    $user_ip = $_SERVER['REMOTE_ADDR'];
    }else{$user_ip = "";}
    
    if(!empty($_SERVER['REMOTE_PORT'])){
    $user_port = $_SERVER['REMOTE_PORT'];
    }else{$user_port = "";}
    
    if(!empty($_SERVER['SERVER_ADDR'])){
    $server_ip = $_SERVER['SERVER_ADDR'];
    }else{$server_ip = "";}
    
    if(!empty($_SERVER['SERVER_PORT'])){
    $server_port = $_SERVER['SERVER_PORT'];
    }else{$server_port = "";}
    
    if(!empty($_SERVER['REQUEST_METHOD'])){
    $request_type = mysql_real_escape_string ($_SERVER['REQUEST_METHOD']);
    }else{$request_type = "";}
    
    if(!empty($_SERVER['HTTP_USER_AGENT'])){
    $browser_type =  mysql_real_escape_string ($_SERVER['HTTP_USER_AGENT']);
    }else{$browser_type = "";} 
    
    mysql_query("INSERT INTO jinendra_statistics.statistics SET url='$url', user_ip='$user_ip', user_port='$user_port', server_ip='$server_ip', server_port='$server_port', request_type='$request_type', browser_type='$browser_type' ");
    
    if(mysql_affected_rows()){
        // it worked, redirect, confirm, etc
    }
    else{
        // it failed
    }
    
    }
    
    ?>
    
    
    <form action="this/page.php" method="post">
    <input type="hidden" name="stats" value="true" />
    <input type="submit" value="Submit Stats" />
    </form>
    

    Try this out. Enter the name of the file you save this as in the action.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made some code which exports some details of a journal article to
I have made some c code for a program, which does some psycho-acoustics on
I have made an SQL query that picks out web statistics from a database.
I have made some changes to a Classic ASP application which breaks foreign letters
I have made some changes in one perforce client, but haven't submitted them. I
I have made some progress with the DataList and UserControl this morning but I
I have made some screenshots of my website, and in internet explorer 6 my
I have made some screenshots of my website, and in internet explorer 6 my
I have a datagrid in C#.net I have made some columns in grid editable.
I posted a thread about this earlier and have made some progress but now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.