Arg I'm stuck
Posted: Tue Oct 24, 2006 8:48 pm
Ok, I'm working on this project for my work (same project I have been working on all week for those who have gernerously helped me out so far).
Here is what is going on. I have written a program that allows teachers (I work at a school) to check out computer cars. The problem is that I am having trouble writing the section of code that deals with cart resrevation cancellation.
Here is what I have so far (I think I am really close but it just is not working): The problem is that currently when a person cancels a cart the program completely erases the carts.txt file. I have a couple of theories as to why but don't really have any idea of where to go from here.
Again, thank you so much for your help and patience as I very slowly and painfully work through my newbie phase.
Here is what is going on. I have written a program that allows teachers (I work at a school) to check out computer cars. The problem is that I am having trouble writing the section of code that deals with cart resrevation cancellation.
Here is what I have so far (I think I am really close but it just is not working): The problem is that currently when a person cancels a cart the program completely erases the carts.txt file. I have a couple of theories as to why but don't really have any idea of where to go from here.
Again, thank you so much for your help and patience as I very slowly and painfully work through my newbie phase.
Code: Select all
$name = trim($_POST['name']);
$cart = trim($_POST['cart']);
$date = trim($_POST['date']);
$reservation = trim($_POST['reservation']); //outputs can only be 'cancel' or 'reserve'
$cart_array = array(
'name' => $name,
'cart' => $cart,
'date' => $date,
'reservation' => $reservation
);
if($reservation == "cancel")// checking to see if user is canceling reservation
{
$eraseData = array(
'name' => "free",
'cart' => "free",
'date' => "free"
);
$file = file("carts.txt"); //get the file as an array
foreach($file as $line)
{
$myline = trim($line); //remove any spaces
$current_cart = unserialize($myline); //unserialize the string and get the stored cart array
$switch_text_file = str_replace($current_cart,$eraseData,$current_cart); //make the replacement
//open text file and switch out reservation info with $eraseData
$temp_string = trim($switch_text_file);
$cart_string = serialize($temp_string);
$fp = fopen("carts.txt","w");
fwrite($fp,$cart_string);
fclose($fp);
}
}