SuzanneB
03-22-2005, 02:37 PM
Hi ALL!!!
Ok I am very new to PHP so not entirely sure what I am doing.
I was looking at this code,
while ($data = fgetcsv ($fp, 500)){
$row++;
if (( $data[0] == $_REQUEST["id"]) && ($data[1] == $full_description)) {
$productfound=true;
break;
}
}
if (!$productfound ) {
if($data[0]!= $_REQUEST["id"])
{
fputs($fp,$_REQUEST["id"].",".$full_description.",".$_REQUEST["price"].",".$_REQUEST["quantity"].",".$_REQUEST["postage"]."\n");
}
}
fclose($fp);
And from what I could see it was opening a file are reading it in one line at a time. It looks for several items of data in the lines of the file and if it does not find them it adds the new line to the end of the file. Firstly, the guy who wrote this software was an idiot so can anyone comment on this code? Is it a sound piece of code! And secondly, when it states "$productfound=true;" I would like to add the code to over-write the existing line with a new line which is similar to the fputs below. My problem here is that my PHP book doesn't have fputs! ha ha! It is a little out of date, so I don't know whether I can just insert the code in under "$productfound=true".
Ok I am very new to PHP so not entirely sure what I am doing.
I was looking at this code,
while ($data = fgetcsv ($fp, 500)){
$row++;
if (( $data[0] == $_REQUEST["id"]) && ($data[1] == $full_description)) {
$productfound=true;
break;
}
}
if (!$productfound ) {
if($data[0]!= $_REQUEST["id"])
{
fputs($fp,$_REQUEST["id"].",".$full_description.",".$_REQUEST["price"].",".$_REQUEST["quantity"].",".$_REQUEST["postage"]."\n");
}
}
fclose($fp);
And from what I could see it was opening a file are reading it in one line at a time. It looks for several items of data in the lines of the file and if it does not find them it adds the new line to the end of the file. Firstly, the guy who wrote this software was an idiot so can anyone comment on this code? Is it a sound piece of code! And secondly, when it states "$productfound=true;" I would like to add the code to over-write the existing line with a new line which is similar to the fputs below. My problem here is that my PHP book doesn't have fputs! ha ha! It is a little out of date, so I don't know whether I can just insert the code in under "$productfound=true".