Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I hope this question is not too basic but I have been working on this script for work (I am a math teacher not a programmer - as you will be able to easily spot from my code.)
Basically here is what the scipt does. On a form webpage, the user supplies some data. On a second page (the php page that I am struggling with) the script opens up a text file and looks to see if that data has already been entered. If so it prints out a warning message. The problem is that when I compare each line in the text file with the user input the script cannot recognize when both pieces of information are the same. I am obviously not grasping something mentally (no surpise there). Please, what am I missing:
Thank you so much in advance for any guidance. Also please do realize I am really, really very new to this whole programming thing - be gentle
code: (I just pulled out the part where the error is occuring)Code: Select all
$fileName = "carts.txt";
$fp = fopen($fileName, "r");
$line = fgets($fp);
//$testLine = trim($line);
//store data in variables
$name = trim($_POST['name']);
$cart = trim($_POST['cart']);
$month =trim($_POST['month']);
$tenDay= trim($_POST['tenDay']);
$oneDay= trim($_POST['oneDay']);
$data=$name.$cart.$month.$tenDay.$oneDay;
$InputData=$data. "\n";
$n = 0; // counter
while (!feof($fp))
{
$line = fgets($fp);
if ("$line" == "$data") // This is where the problem is. The program keeps going to the else part of this statement even though the information that is exactly the same.
{
print "Somone has already checked out this cart";
}
else
{
print "$data <br />";
print "$line";
}
}Everah | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]