Page 1 of 1

upload text file and fetch data

Posted: Tue Nov 08, 2016 12:13 am
by uahmed82
Hi I have a student form

Code: Select all

<?php 
   $fonts = "verdana";
   $fontcolor = "#3A9BE8";
   $bgcolor = "#faaa3c";
?>

<!doctype html>
<html>
<head>
   <title>Php Syntax</title>
   <style>
      body{
         font-family:<?php echo $fonts;?>
         
      }
      .phpcoding{
         width: 900px;
         margin: 0 auto;
         background: #ddd;
         
         min-height:400px;
      }
      
      .headeroption, .footeroption{
         background:#444;
         color:<?php echo $fontcolor; ?>;
         text-align: center;
         padding: 20px;
      }
      .headeroption h2, footeroption h2{
         margin:0;
      }
      .maincontent{
         min-height:400px;
         padding: 20px;
         background:<?php echo $bgcolor;?>
      }
   </style>
</head>
<body>

<div class="phpcoding">
   <section class="headeroption">
      <h2>Student Data</h2>
   </section>
   
   <section class="maincontent">      
      <div class = "student_data">
         <form action = "" method = "post">
            <table>
               <tr>
                  <td>Name</td>
                  <td><input type = "text" name = "name" /></td>
               </tr>
               
               <tr>
                  <td>City</td>
                  <td><input type = "text" name = "city" /></td>
               </tr>
               
               <tr>
                  <td>Exam Date</td>
                  <td><input type = "date" name = "examDate" /></td>
               </tr>
               
               <tr>
                  <td>Browse to upload file... </br></td>
                  <td><input type = "file" name = "browseFile" /></td>
               </tr>                           
               
               <tr>
                  <td></br></td>
                  <td><input type = "submit" name = "uploadFile" value = "Upload"/></td>
               </tr>   
               <tr>
                  <td></br></td>
                  <td><input type = "submit" name = "save" value = "Save"/></td>
               </tr>                  
            </table>
         </form>
      </div>
   </section>
   
   <section class="footeroption">
      <h4> <?php echo "&copy All rights reserved" ?></h4>
   </section>
      
</div>

</body>
</html>
I have a text file "marks.txt". the text file looks like this. 3 terms marks are there for Math, Economics & English.
Math
80
55
90
Economics
59
22
60
English
83
68
76
I want to upload the data from this text file to MySQL table. I just need the numbers, so how can I avoid the String (Math, Economics and English).
please help me. I don't know how to get data from text file.

Re: upload text file and fetch data

Posted: Tue Nov 08, 2016 7:16 am
by Celauran
Start here and let us know where you get stuck: http://php.net/manual/en/function.fgets.php

Re: upload text file and fetch data

Posted: Tue Nov 08, 2016 9:37 am
by Christopher
For the file upload, start here: http://php.net/manual/en/features.file-upload.php

Once you have uploaded the file, you can read it into an array with: http://php.net/manual/en/function.file.php