BIG help needed

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
davy2001
Forum Commoner
Posts: 37
Joined: Tue Feb 24, 2004 5:59 pm

BIG help needed

Post 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)
?>
Last edited by davy2001 on Tue Mar 09, 2004 7:22 am, edited 5 times in total.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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?
davy2001
Forum Commoner
Posts: 37
Joined: Tue Feb 24, 2004 5:59 pm

Post 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)
Post Reply