wobuck Posted September 15, 2008 Share Posted September 15, 2008 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 Link to comment https://forums.phpfreaks.com/topic/124367-cannot-get-data-to-display-from-csv-file/ Share on other sites More sharing options...
adam291086 Posted September 15, 2008 Share Posted September 15, 2008 edit sorry sorry just read your code but this line is point less $serial = $_POST['serial']; put error_reporting(E_ALL); at the top of the page and see what you get Link to comment https://forums.phpfreaks.com/topic/124367-cannot-get-data-to-display-from-csv-file/#findComment-642295 Share on other sites More sharing options...
wobuck Posted September 22, 2008 Author Share Posted September 22, 2008 Apologies for delay in response - yes you are correct the line is not needed. Problem now solved - it was the sparsing bit where I was looking for ; which was the wrong character should have been a comma! Many thanks! Link to comment https://forums.phpfreaks.com/topic/124367-cannot-get-data-to-display-from-csv-file/#findComment-647441 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.