Page 1 of 1

BIG help needed

Posted: Tue Mar 09, 2004 6:24 am
by davy2001
can someone please tell me why this doesnt work:

Code: Select all

<?

/////////////////////////////////
//collect varriables to be used//
/////////////////////////////////

//get pass user defined
$name=$_POST['name'];
$subject=$_POST['subject'];
$period=$_POST['period'];
$day=$_POST['day'];

/////////////
//functions//
/////////////

//log booking
$fp = fopen("bookings.txt", "a");
$string = "&$day$period=$name - $subject \r\n";
$write = fputs($fp, $string);
fclose($fp);

//Check if in use
$txt_file = fopen("bookings.txt", "rb"); 
while($file_line = fgets($txt_file)){ 
    $line_array = explode(",", $file_line); 
    $username = $line_array[0]; 
    
    if($username == &$day$period){ 
        echo "That name is taken!"; 
    } 

} 


header ('Location: upmicro.html');

?>
i want it to check if a certain day/period has been booked (//Check if in use)

Dave (http://www.flashworld.co.uk)
?>

Posted: Tue Mar 09, 2004 6:32 am
by markl999
You appear to be writing to the file in the format "&$day$period=$name - $subject \r\n"; ... but reading in and exploding on , ? There's no comma in that format.

Also, you write to the file before checking if it's taken?
if($username == &$day$period){ looks like it should be at least if($username == "&$day$period"){ .. and are you sure username is a copmbination of &$day$period ? Sounds weird for a username, and you also have a $name variable..what's that if it's not a username?

The layout and variable names make it hard to work out exactly how it's supposed to work, maybe add some more comments explaining what's going on?

Posted: Tue Mar 09, 2004 6:37 am
by davy2001
the $username is uhh i dunno, im kind of confused myself

i want it to ready the text file (bookings.txt) and check for any lines starting with '&$day$period'

Dave (http://www.flashworld.co.uk)