0

//output Start

Output File:-05012015.txt

  This is of my output of file which is the mapper file used for the verification But all below no are store in the database .That No Description  are as follow


            34012015000180001000631931058620000607262Y22122014 N                   


Above All Digits- 34 :-Contant value
                  01201500018 :-record number 
                  0001000631931058620 :-Doc No
                  000607262 :-Product Code
                  Y :-status
                  22122014 :date format DD/MM/YYYY
                    :-one Blank Space
                  N :- Status
                    :-Remaining Blank Spaces

Above Description of record which store different column in the database...

//Output End

when the text file display the contents that contents including all no,characters,blank spaces and other blank spaces of records ends in the file which store in the different column.

When I click on the Second Submit Button then store Data int Mysql Database.
I want to store all contents of text file including all no,characters,blank spaces and other blank spaces of records in the mysql database.

PHP & HTML Code:-

        Below is the my PHP with HTMl Code 

        <html>
        <style>
        span{color: #FF0000;}
        </style>
        <body>
        <script type="text/javascript">
        function validate()
        {
        if( document.myForm.photo.value == "" )
           {
             alert( "Please Upload File!" );
             document.myForm.photo.focus();
             return false;
           }
            return( true );
        }
        </script>
        <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" enctype="multipart/form-data" name="myForm" onsubmit="return(validate());">
        Attach Mapper File:-<input type="file" name="photo" size="140"> <span>[Select Only  .TXT fle]</span>&nbsp;&nbsp;&nbsp;
         <input type="submit" name="submit" value="Submit">&nbsp;&nbsp;&nbsp;
        <br ><br> <br> 

        </form>

        </body>
        </html>

        ===================================================================================================================================================
        <b>File Name:-&nbsp;&nbsp;&nbsp;<?php
        // escape variables for security
              $pic=( $_FILES['photo']['name']);
         echo basename($pic) . "<br/>";?><br> 
        File Description:-</b><br><br><br> 

        <?php

        $file=fopen ("test/$pic","r") or exit("Error");
        $data="";

        while(!feof($file))
        {

          $data .= "<pre>" . fgets($file) . "<br/>";
        }

        fclose($file);
        echo $data;

        ?>
        =====================================================================================================================================================================
        <html>
        <body>
         <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
         <input type="submit" name="submit2" value="Submit">&nbsp;&nbsp;&nbsp;
        </form>
        </body>
        </html>

//Code End

Mysql Table Syntax:-

CREATE TABLE test(
id int(5) NOT NULL AUTO_INCREMENT,
no1 varchar(40)  NOT NULL,
no2 varchar(40),
no3 varchar(40),
no4 varchar(40),
no5 varchar(40),
no6 varchar(40),
no7 varchar(40),
no8 varchar(40),
no9 varchar(40),
PRIMARY KEY (id))
engine=InnoDB;
2
  • 1
    Use file_get_contents to get content from file. Commented Apr 16, 2015 at 9:23
  • ok that work but how can i store it in database Commented Apr 16, 2015 at 10:32

1 Answer 1

1

Just store the content in variable & then store it in database using MySQL query.

Do like this:

$content = file_get_content('Your File');
$query = "INSET INTO table (field) VALUES ('".$content."')";

Let me know for more help!

Sign up to request clarification or add additional context in comments.

1 Comment

Below no of digits which is display the descrption in above my file that digits store seperate in the database column..and also give u my database table syntax as above so please help.......... 34012015000180001000631931058620000607262Y22122014 N

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.