John Davidson

html - Unable to submit values from CSV to php

0 comments
Message:


This is my first attempt at PHP and therefore have minuscule knowledge of php.
I am trying to make a form that would get values from a csv --> allow to select multiple values --> post to a php file.
I can get the table to display and select multiple values but upon submit nothing happens.
Here is the code snippet. Appreciate any help with the fix


<form action="Test.php" method="POST">
<label for="Cluster"><br><br><b>Choose Clusters:</b><br></label>
<br>
<select name="Cha_Cluster[]" id="cha_Cluster" size ="15" multiple>
<?php
$fileHandle = fopen("cha_cluster.csv", "r");
while (($row = fgetcsv($fileHandle, 0, ",")) !== FALSE) {
$cha_cluster = $row[0];
?>
<option value="<?php echo $cha_cluster;?>"><?php echo $cha_cluster;?></option>
<?php
}
?>
</select>
<br><br>
<input type="submit" name="submit" id="submit" value="Submit" />
</form>
<?php
if (isset($_POST["cha_cluster"]))
{
print_r ($_POST["cha_cluster"]);
}
?>


My Answer:
file and submit them to a PHP script for processing. However, I am unable to get the values from the CSV file and submit them to the PHP script. Can someone please help me with this?

Here is my HTML form code:

html






And here is my PHP script (process.php) code:

php
if(isset($_FILES['csvfile'])){
$file = $_FILES['csvfile']['tmp_name'];
$handle = fopen($file, "r");

while(($data = fgetcsv($handle, 1000, ",")) !== FALSE){
$value1 = $data[0];
$value2 = $data[1];

// Process the values here
echo "Value 1: " . $value1 . "
";
echo "Value 2: " . $value2 . "
";
}

fclose($handle);
}
?>


When I select a CSV file and click on the submit button, nothing happens. The values from the CSV file are not being processed by the PHP script. Can someone please help me with this issue and guide me on how to correctly submit values from a CSV file to a PHP script? Thank you.

Rate this post

4 of 5 based on 6197 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us