value recorded in the database differs from the value of the variable

I am trying to save a file in php, and the name of the file is being changed using the date, time and a random number. The same name of the file is being recorded in a database, however the name of the record in the database differs always of a few digits from the one being generated and used for the file upload. It looks like when the operation of uploading of the file occurs, the random number is being regenerated…:( but a that should be happening.

<?php
$id = intval($_REQUEST['id']);

include 'conn.php';

$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);

$today = date('y-m-j');
$time1 = date('H-i', time()); // 12:50:29

$temp = mt_rand ( 0 , 200 );

$newfilename = $today.'_'.$temp.'_'.$time1.'.zip'; //generates a random name based on time for the 

$DBnewfilename="http://localhost/purchasesystem/uploads/".$newfilename;


$sql = "update PURCHASE_REQUESTS set URL='$DBnewfilename' where id=$id";         

$result = @mysql_query($sql);



    if(move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], "uploads/".$newfilename)){

            echo "The file ". basename($_FILES["fileToUpload"]["name"]). " has been uploaded.";

    } else {
            echo "Sorry, there was an error uploading your file.";
        }

the database record URL is set as TEXT (however I have tried also varchar with no results) 😦

thanks a lot for any advise you could possibly give me.
Kele

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s