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 7747619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:34:31+00:00 2026-06-01T10:34:31+00:00

Hi i have a small query which takes data from one mysql database and

  • 0

Hi i have a small query which takes data from one mysql database and inserts it into a duplicate table, the problem is i get the relevant data out of the database fine, but i can not seem to get it in to the new database, i have error reporting enabled, but i am not getting any errors.

Below is my code:

$dbhost                         = "";
$dbuser                         = "";
$dbpass                         = "";
$dbname                         = "";
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ("Error connecting to  database");
mysql_select_db($dbname);
$result = mysql_query("SELECT * FROM ip_stats WHERE DATE(date) = CURDATE()") 
or die(mysql_error());  
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
    $id   = $row['id'];
    $date   = $row['date'];
    $ip   = $row['ip'];
    $hostname   = $row['hostname'];
    $company_name   = $row['company_name'];
    $address   = $row['address'];
    $descr   = $row['descr'];

    echo "$id - $date - $ip - $hostname - $company_name - $address - $descr"; 
    ?>
    <br />
    <?php
    $query = "INSERT INTO `ip_stats11` (`id`, `ip`, `date`, `hostname`, `company_name`, `address`, `descr`, `updated`)
      VALUES ('$id', '$ip', '$date', '$hostname', '$company_name', '$address', '$descr', 'yes')";
    echo "updated $ip"; ?><br /><?php
}
  • 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-01T10:34:34+00:00Added an answer on June 1, 2026 at 10:34 am

    @klijn is probably right that you forgot to execute the INSERT query.
    However, I would advise to do this simpler and faster:

    $result = mysql_query('
        INSERT INTO `ip_stats11` (
            `id`, `ip`, `date`, `hostname`, `company_name`, `address`, `descr`, `updated`
        )
        SELECT ip_stats.*, 'yes' 
        FROM   ip_stats 
        WHERE  DATE(date) = CURDATE()
    '); 
    

    One other thing – this construct:

    WHERE  DATE(date) = CURDATE()
    

    Might not be very efficient. You apply a function to the date column. If that is of the DATE datatype, you don’t need that and you should leave it out. If it is a DATETIME and you want to truncate the time part, then doing it this way will make it impossible for mysql (and most other RDBMS-es too) to use any indexes on that column.

    Here’s a better way:

    WHERE  `date` BETWEEN CURRENT_DATE
                      AND CURRENT_DATE + INTERVAL 1 DAY - INTERVAL 1 SECOND
    

    The way this works is that CURRENT_DATE will be cast to a DATETIME (assuming the date column is a DATETIME or TIMESTAMP, and it will have a zero timepart, indicating the start of that day and the start of our BETWEEN…AND range. For the end of the range, we say: please use tomorrow:

    CURRENT_DATE + INTERVAL 1 DAY
    

    Which is in fact the first second of the 1 day later than current_date. This is not entirely correct, because BETWEEN...AND... uses inclusive range boundaries, so we substract one second with the - MINUS 1 SECOND to ensure we got the very last second of the day indicated by CURRENT_DATE.

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

Sidebar

Related Questions

I have a query which shows all images from a user. (In this case
I have a query which shows all images from a user. (In this case
I have a problem with a small query. When I execute it I am
I have a small ruby app in which I'm trying to query some information
I have a database in production with one table that has grown extremely large
I have a big query which is all written in small letters. Is there
I have a small app which query our SharePoint server' Web Service interface for
I have a small problem with an SQL query. Maybe I just couldn't wake
i have small query as follows: If i will make view state property of
I have this small SQL query. SELECT a.`id` , a.`title` , a.`date` , (

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.