Bluehost.com Web Hosting $6.95

Enough is Enough.......

This is a discussion on Enough is Enough....... within the PHP General forums, part of the PHP Programming Forums category; Hi, I apologize for all the emails on this, but I'm truly at a loss here and really need ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-19-2003
Beauford.2005
 
Posts: n/a
Default Enough is Enough.......

Hi,

I apologize for all the emails on this, but I'm truly at a loss here and
really need some input as to what I need to do to get this working.

I have a FORM with two drop down menus and have the entries saved in two
separate .inc files i.e:

<Option Value="3">Alfredsson
<Option Value="39">Arnott
<Option Value="150">Aucoin
<Option Value="143">Audette
Etc...

<Option Value="67">Bates
<Option Value="36">Battaglia
<Option Value="152">Berard
<Option Value="6">Bertuzzi
Etc....

The user enters the webpage and chooses a player from list one and list
two. This gets submitted to my PHP script which reads in these files and
manipulates them accordingly and re-saves them. At the end of the PHP
script I include the input file again - include("injury-input.php") -
which should now have the updated drop down menus.

This seems to work the first time you open up a browser and go to the
input page (although I can't really even be sure of that now). If you
try to do it again using a different set of players, it doesn't work. I
usually end up with two empty files. So it appears it is opening the
file the second time ok, but is not writing to it.

I have no idea what to do with this.

Here is the script:

function writeplayer($from_row, $to_row) {

include("trade-errors.inc");

$filename = "players.inc";

$fd = fopen ($filename, "r");
$content = "";
while (!feof ($fd)) {
$content = fgets($fd);
if (preg_match ("/".$to_row['player']."/", $content)) { }
else { $list[] = $content; }
}
fclose ($fd);

$num = count($list);
$list[$num] = "\r\n<Option
Value=\"".$from_row['idp']."\">".$from_row['player'];
$num = count($list);

$list = preg_replace('/(<.*?>)(.*)/', '$2$1', $list);
sort ($list);
$list = preg_replace('/(.*?)(<.*>)/', '$2$1', $list);

if (is_writable($filename)) {

if (!$fp = fopen($filename, 'w')) {
$injury_errors = $playeropens;
include("injury-input.php");
exit;
}
for($i=0; $i < $num; $i++) {
if (!fwrite($fp, $list[$i])) {
$injury_errors = $playerwrite;
include("injury-input.php");
exit;
}
}
fclose($fp);
}
else {
$injury_errors = $notwritable;
include("injury-input.php");
exit;
}

unset($list); unset($content); unset($num); unset($filename);
unset($fd); unset($fp);
writereserve($from_row, $to_row);
$injury_errors = $updated;
return($injury_errors);

}

function writereserve($from_row, $to_row) {

include("trade-errors.inc");

$filename = "players-reserve.inc";

$fd = fopen ($filename, "r");
$content = "";
while (!feof ($fd)) {
$content = fgets($fd);
if (preg_match ("/".$from_row['player']."/", $content)) { }
else { $list[] = $content; }
}
fclose ($fd);

$num = count($list);

if (is_writable($filename)) {

if (!$fp = fopen($filename, 'w')) {
$injury_errors = $playeropens;
include("injury-input.php");
exit;
}
for($i=0; $i < $num; $i++) {
if (!fwrite($fp, $list[$i])) {
$injury_errors = $playerwrite;
include("injury-input.php");
exit;
}
}
fclose($fp);
}
else {
$injury_errors = $notwritable;
include("injury-input.php");
exit;
}

$injury_errors = $updated;
unset($list); unset($content); unset($num); unset($filename);
unset($fd); unset($fp);
return($injury_errors);

}

Reply With Quote
  #2 (permalink)  
Old 07-19-2003
Curt Zirzow
 
Posts: n/a
Default Re: [PHP] Enough is Enough.......

Beauford.2005 <beauford.2005@rogers.com> wrote:
> Hi,


Hello

> [...]
>
> $list = preg_replace('/(<.*?>)(.*)/', '$2$1', $list);
> sort ($list);
> $list = preg_replace('/(.*?)(<.*>)/', '$2$1', $list);


what is list after the first preg and after the second one, that regex
doesn't look safe to me.

Do you have access to a database? This task would be a whole lot easier
to do, plus a whole lot more safer.

Curt
--

Reply With Quote
  #3 (permalink)  
Old 07-20-2003
Beauford.2005
 
Posts: n/a
Default RE: [PHP] Enough is Enough.......

Done. You must have read my mind. I just finished putting the whole
thing in MySQL - since I am using it anyway to hold all my other data it
was easy to do. Took me about 45 minutes to do this as opposed to a week
with the other, and it still didn't work. I'd still be curious to why
the other is didn't work though. I know my logic is correct, but maybe
what I was trying to do just wasn't feasible.

Thanks for the input.

-----Original Message-----
From: Curt Zirzow [mailto:curt@zirzow.dyndns.org]
Sent: July 19, 2003 2:33 AM
To: PHP
Subject: Re: [php] Enough is Enough.......


Beauford.2005 <beauford.2005@rogers.com> wrote:
> Hi,


Hello

> [...]
>
> $list = preg_replace('/(<.*?>)(.*)/', '$2$1', $list);
> sort ($list);
> $list = preg_replace('/(.*?)(<.*>)/', '$2$1', $list);


what is list after the first preg and after the second one, that regex
doesn't look safe to me.

Do you have access to a database? This task would be a whole lot easier
to do, plus a whole lot more safer.

Curt
--


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Reply With Quote
  #4 (permalink)  
Old 07-22-2003
Marek Kilimajer
 
Posts: n/a
Default Re: [PHP] Enough is Enough.......

I used to have the same problem. It seems it's not safe to include a
file you have just writen.

Beauford.2005 wrote:
> Done. You must have read my mind. I just finished putting the whole
> thing in MySQL - since I am using it anyway to hold all my other data it
> was easy to do. Took me about 45 minutes to do this as opposed to a week
> with the other, and it still didn't work. I'd still be curious to why
> the other is didn't work though. I know my logic is correct, but maybe
> what I was trying to do just wasn't feasible.
>
> Thanks for the input.


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:29 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0