0

Hi...i would like to save and edit some excel files located in server using php. The coding below upload the file but when i open the page again...the message 'no file chosen' appears. Please help on this matter...thanks a lot...

<?php
error_reporting(E_ALL ^ E_NOTICE);
$_SESSION['Targetid'];
$_SESSION["Progressid"];
$conn = mysql_connect("localhost","pqa","");
mysql_select_db("pq",$conn);

if(count($_POST)>0) {

mysql_query("UPDATE progress set Attachment2='" . $_POST["Attachment2"] . "',
Attachment21='" . $_POST["Attachment21"] . "' WHERE Progressid='" . $_SESSION["Progressid"] . "'");
$message = "Record Modified Successfully";

}

$result = mysql_query("SELECT * FROM progress WHERE Progressid='" . $_SESSION["Progressid"] . "'");
$row= mysql_fetch_array($result);
?>
<html>
<head>
<title>Add New User</title>
<link rel="stylesheet" type="text/css" href="styles.css"/>
</head>
<body>
<form name="<?php echo $_SERVER['PHP_SELF']?>" method="post" action="">
<div style="width:500px;">
<div class="message"><?php if(isset($message)) { echo $message; } ?></div>
<div align="right" style="padding-bottom:5px;"><a href="list_progress2.php" class="link"><img alt='List' title='List' src='images/list.png' width='15px' height='15px'/> List Progress</a></div>
<p><b>1.Target</b></p>
<ENCTYPE="multipart/form-data">c.i.Preformatted Forms: <input type="file" name="Attachment2" MAXLENGTH=50 ALLOW="text/*" value="<?php echo $row['Attachment2']; ?>"><br>
<ENCTYPE="multipart/form-data">c.ii.School/Department Forms: <input type="file" name="Attachment21" MAXLENGTH=50 ALLOW="text/*" value="<?php echo $row['Attachment21']; ?>"><br>
<input type="hidden" name="Targetid" ><br>
<td colspan="2"><input type="submit" name="submit" value="Submit" class="btnSubmit"></td>
</div>
</form>
</body></html>

Edited by Sophia_1

2
Contributors
2
Replies
30
Views
2 Years
Discussion Span
Last Post by Sophia_1
0

You need to do this with a csv file.

    //Upload File
51  if (isset($_POST['submit'])) {
52      if (is_uploaded_file($_FILES['filename']['tmp_name'])) {
53          echo "<h1>" . "File ". $_FILES['filename']['name'] ." uploaded successfully." . "</h1>";
54          echo "<h2>Displaying contents:</h2>";
55          readfile($_FILES['filename']['tmp_name']);
56      }
57   
58      //Import uploaded file to Database
59      $handle = fopen($_FILES['filename']['tmp_name'], "r");
60   
61      while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
62          $import="INSERT into tablename(item1,item2,item3,item4,item5) values('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]')";
63   
64          mysql_query($import) or die(mysql_error());
65      }
66   
67      fclose($handle);
68   
69      print "Import done";
70   
71      //view upload form
72  }
0

Hi...thanks a lot for your fast reply...sorry for not being specific...actually i just want to upload the excel file to server and whenever i want to edit the file, i just open the page and click on the file to edit it...currently there is no need to import uploaded file to database...please advise,thanks.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.