javascript - using onclick function to store CSV file to database -


<i>i ask how store csv file database after upload html form. had tried use onclick store csv file database , work. @ same time need validate other fields in form cannot make using onclick function. in project integrate javascript php code , know cannot done. can me solve problem? jest need store csv file database , validate other fields.

`

<?php   require_once "lib/base.inc.php"; ?>  <script> function checkmail(){ var subject = document.getelementbyid('subject').value; var message = document.getelementbyid('message').value; var csv = document.getelementbyid('csv').value;  if(empty(subject)){ alert("subject required."); } else if(empty(message)){ alert("message required."); } else if(empty(csv)){ alert("csv file required."); }  else{ <?php      $file = $_files[csv][tmp_name];      $handle = fopen($file,"r");       //loop through csv file , insert database      {          if ($data[0]) {              $record['contact_first'] = $data[0];             $record['contact_last'] = $data[1];             $record['contact_email'] = $data[2];             $record['status'] = 0;              $oadminemail->insertqueemail($record);             }      } while ($data = fgetcsv($handle,1000,",","'"));       ?>;  } } </script> <html xmlns="http://www.w3.org/1999/xhtml">  <head>  <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />  <title>import csv file php & mysql</title>  </head>  <body>  <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">    subject : <br/>   <input type="text" name="subject" id="subject"/> <br/>   choose file: <br />    <input name="csv" type="file"id="csv"/> <br/>   content : <br/>   <textarea name="message" cols="50" rows="10"></textarea><br/>   <input type="submit" name="submit" value="submit" onclick="checkmail()"/>  </form>  </body>  </html>` 

you should add accept=".csv" attribute input.

<input type="csv" name="file" id="csv" accept=".csv"> 

i have tried code , found upload type of file. since code cannot run alert message using javascript. therefore, alternative way add accept filter particular file format display avoid unnecessary error.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -