Jump to content

Cannot get data to display from CSV File?


wobuck

Recommended Posts

I am very new to php and suspect I have made a coding error.

 

1) I created an HTML form:

 

<html>

 

<head>

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

<title>Serial Number</title>

</head>

 

<body>

 

<form method="GET" action="prop2.php">

 

<!--&beds=-->

Serial<br /><br />

<select class="formboxsize" size="1" name="serial">

<option value="1" selected>1</option>

<option value="2">2</option>

<option value="3">3</option>

 

</select><br /><br />

 

<input type="submit" name="submit" value="Submit"></div>

</form>

 

</body>

 

</html>

 

2) Then I created a PHP file;

 

<?php

$file = "xfile.csv";

 

$serial = $_POST['serial'];

 

 

if ( !empty ( $_GET['serial'] ) ) {

 

$serial = $_GET['serial'];

 

$file_content = file_get_contents ( $file );

$file_arr = preg_split ( '/\n/' , $file_content );

$found = false;

 

foreach ( $file_arr as $item ) {

$data = explode ( ';' , $item );

if ( $data[0] === $serial ) {

$found = true;

$date = $data[1];

 

}

}

if ( $found ) {

print "Date: " . $date;

}

else {

print "Not found";

}

}

?>

 

3) The xfile.csv file contains:

 

serial date Warranty

1 01/01/2008 01/01/2009

2 24/02/2008 23/01/2009

3 10/10/2008 09/09/2009

 

4) When I run the form it returns "Not found"

 

If I change the php file command $found = false; to true it displays the word Date: as expected, but no data from the file?

 

:(

 

Any help would be greatly appreciated?

 

Wobuck

 

:)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.