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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:39:44+00:00 2026-05-21T23:39:44+00:00

Following on from a previous question I posted, which I managed to get working

  • 0

Following on from a previous question I posted, which I managed to get working great, I’m now stuck trying to check and store the date of the csv file and then execute the script if the csv file is newer. I plan on running a cron job when this is working properly in order to check regularly for a newer csv file. I just can’t seem to be able to work out why the date and csv file aren’t being updated into the database when I manually add a modified csv file to the directory and then run the script manually.

Any help greatly appreciated, S.

Current code:

            $stat = stat('../data/filename.csv');   
            $datetime = date ("F d Y H:i:s.", $stat['mtime']);
            $datetime = mysql_real_escape_string($datetime);
            $datetime = strtotime($datetime);
            $datetime = date('Y-m-d H:i:s',$datetime);              
            echo "<br />Last modified: " . $datetime;                   

            $query=mysql_query("select * from iscsvtime");
            $dateResult=mysql_fetch_array($query);          
            $stored = $dateResult['added'];             

            if (($stored <= $datetime) && ($handle = fopen("../data/filename.csv", "r")) !== FALSE) {
                $i=0;
                echo "<br />Stored date: " . $stored;
                mysql_query("INSERT INTO iscsvtime(added) VALUES ('$datetime')");                                   
                mysql_query('TRUNCATE TABLE isstock;'); 
                while (($data = fgetcsv($handle, 0, ",")) !== FALSE) 
                {                    
                    if($i>0){                           
                        $q="insert into isstock set feedid='".$data[0]."', vehicleid='".$data[1]."', registration='".$data[2]."', colour='".$data[3]."', fueltype='".$data[4]."', year='".$data[5]."', mileage='".$data[6]."', bodytype='".$data[7]."', doors='".$data[8]."', make='".$data[9]."', model='".$data[10]."', variant='".$data[11]."', enginesize='".$data[12]."', price='".$data[13]."', previousprice='".$data[14]."', transmission='".$data[15]."', picturerefs='".$data[16]."', servicehistory='".$data[17]."', previousowners='".$data[18]."', description='".$data[19]."', fourwheeldrive='".$data[20]."', options='".$data[21]."', comments='".$data[22]."', new='".$data[23]."', used='".$data[24]."', site='".$data[25]."', origin='".$data[26]."', v5='".$data[27]."', condit='".$data[28]."', exdemo='".$data[29]."', franchiseapproved='".$data[30]."', tradeprice='".$data[31]."', tradepriceextra='".$data[32]."', servicehistorytext='".$data[33]."', capid='".$data[34]."'";                    
                        mysql_query($q);
                    }
                    ?>
                        <tr>
                            <?php
                            foreach($data as $rec){
                                echo '<td>'.$rec.'</td>';
                            }
                            ?>
                        </tr>
                    <?php
                    $i++;
                }
            }
            fclose($handle);

EDIT: Turns out I managed to fix this myself; just had to change the if statement slightly and change the INSERT INTO iscsvtime to an UPDATE. Updated code below:

                if (($datetime > $stored) && ($handle = fopen("../data/filename.csv", "r")) !== FALSE) {
                $i=0;                   
                mysql_query("UPDATE iscsvtime SET added = '$datetime' WHERE id = '0'");
  • 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-05-21T23:39:45+00:00Added an answer on May 21, 2026 at 11:39 pm

    I’d be inclined to say that the mixing of single and double quotes is not helping your cause. This inconsistency may be leading to any number of possible errors, where it doesn’t already impede readability.

    Lines such as

    echo "<br />Stored date: " . $stored;
    

    could be replaced by

    echo "<br />Stored date: {$stored}";
    

    or use the same notation as later in the script

    echo '<td>'.$rec.'</td>';
    

    I believe this could be tripping up your SQL statement

    mysql_query("INSERT INTO iscsvtime(added) VALUES ('$datetime')");
    

    Try changing it to

    mysql_query("INSERT INTO iscsvtime(added) VALUES ('{$datetime}')");
    

    In addition to this, you could add some error logging by making use of the mysql error functions php.net/mysql_error, like so:

    if(!mysql_query("INSERT INTO iscsvtime(added) VALUES ('{$datetime}')"))
    {
        echo mysql_errno . ': ' . mysql_error();
    }
    

    Other things to check include, correct location of file on disk as referenced in the functions that need it, is the file empty and finally, does the insert statement match the layout of the table, i.e. if the table has more than one column, are the non-provided columns set to allow NULL values, otherwise, these should be defined in the insert statement.

    Hope this helps

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

Sidebar

Related Questions

Following on from my previous question , I have now managed to rotate my
Following on from a previous question i asked, I'm now trying to figure out
Following on from a previous question, I'm trying to clean up some data where
Following on from a previous question in which I asked: How can I use
Following on from my previous question , which was so quickly answered by Meder
Following on from my previous question about tables I am trying to create additional
I have the following code (from a previous question on this site) which retrieves
Following on from my previous question I have been working on getting my object
Following on from my previous question, Python time to age , I have now
Following up from my previous question , why is CShell so different from C?

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.