0

I'm not quite sure where to start with this one... I have a .csv file with two columns.

User, computer name
john, computer1
jane, computer2

I've got an html page that can be seen below:

<HTML>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%"> 
<HEAD>
<TITLE >
User Login
</TITLE>
<form name="input" method="post"
action="/tinkering.php">

<p><label for="firstname">User Name: </label>
<input type="text" name="fname" id="fname" /></p>

<p><label for="idnumber">Password: </label>
<input type="text" name="idnumber" id="idnumber" /></p>

<p><input type="reset" name="reset" value="reset" />
<input type="submit" name="submit" value="submit" />
</form>
</HTML>

I also have the following php script

<?php

if (isset($_POST['submit'])) {

$userInput = $_POST['userInput'];
$array = file('test.csv');
$match_found = false;
foreach ($array as $line) {
$pieces = explode(",",$line);
if ((trim($pieces[0]) == $userInput)) {
$match_found = true; break;
}
}
if($match_found){
echo 'Your computer name has been found...';

## not sure how to create variable here,but ideally 
## that would happen at this point, and the user would continue with login 
## process...


} else {
echo 'Could not find computer name...';
}
}

?>

however, when i go to the html form, fill out my information, and click 'submit' I receive the following message:

_

Your file was not found

It may have been moved or deleted.

ERR_FILE_NOT_FOUND

_

I'm sure i'm missing something silly, but I'm at a loss as to what i need to do to get this up and running.

Honestly i'm not even sure if i'm even going in the right direction.

Thanks in advance for any assistance you can provide on this issue.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
sms5138
  • 47
  • 3
  • I don't see a matching name attribute for `$_POST['userInput']`, *do you?* – Funk Forty Niner Apr 04 '17 at 15:22
  • also; "how" this is being accessed will matter. Are you doing `http://localhost` (or hosted) or directly in the browser as `file:///`? These are questions that need to be answered. Also check your path/filename. – Funk Forty Niner Apr 04 '17 at 15:23
  • Your HTML markup is invalid btw. – Funk Forty Niner Apr 04 '17 at 15:26
  • *"Thanks in advance"* - Comments like that (to me) say that you stand to wait for answers/solutions and not bother answering to comments; ones I've left. So, if you left the question only to return at a later date, well one will not have been provided by *"Your truly"*. It's your job to find out why your code failed and debug it. I've asked for clarification; now the "ball is in your court". So, *"what say, ye?"* – Funk Forty Niner Apr 04 '17 at 15:28
  • edit: My apologies I didn't realize that comment could be taken that way.. my html i uploaded was a slightly different version.. one of the solutions i was trying out used "fname" instead of "userInput" (silly of me for sure)... i'm currenlty testing this using wamp. So i've updated that and added 'action= "file:///C:/wamp64/www/tinkering.php"' now when I run it it does seem to find the file, but just shows me the php script... I am actively working to figure this out, but i feel like i've hit a wall... @Fred-ii- could you clarify what you mean by "Your HTML markup is invalid btw." – sms5138 Apr 04 '17 at 15:47
  • check the duplicates; all of those contain enough information for you to run it successfully. Your usage of `file:///` is the main cause here, look at my second comment. As for your HTML markup: you have `` inside `` and a missing `
    ` tag as well as ``. Here is a quick guide https://www.w3schools.com/html/html_intro.asp
    – Funk Forty Niner Apr 04 '17 at 15:50
  • Thank you @Fred-ii- for your help with this... i ended up figuring it out... i think i was just a bit too focused on the next part of my project that i tried to rush through this one... which inevitably created my issues... just need to slow down i guess :p I ended up finding what i needed here [link](http://stackoverflow.com/questions/6426762/php-find-string-in-csv-file) ... Thank you again for all your help today! – sms5138 Apr 04 '17 at 18:54
  • you're most welcome, glad to see it all worked out for you, *cheers* – Funk Forty Niner Apr 04 '17 at 18:55

0 Answers0