Jump to content

[SOLVED] Help With adding and deleteing from a file


g7psj

Recommended Posts

Hi all im a bit new to php

 

I am trying to add to a php file called dates.php from a html form page in the following format.

 

Date,TimeFrom,TimeTo,Destination

20071019,0815,1630,TTraining.php

20071022,0815,1630,Holiday.php

 

Basicaly its a file used by  Voicexml on a linux based phone system  to determin the destination of a call on a specific date which needs to be in a csv format..

 

I have the HTML page with a form which posts the results to a submit.php page the php page adds to a file called dates.php

 

However i cannot get it to format it as above all i get is:

 

Date,TimeFrom,TimeTo,Destination

20071019,0815,1630,TTraining.php

20071022,0815,1630,Holiday.php

2007

01

01

, 0800

, 1800

, Night.php

 

Here is the code from the html page

 

<html>

<head>

<title>Send</title>

</head>

<body bgcolor="#000000" text="#FF0000" link="#FF0000" vlink="#FF0000">

<form name="subscribe" action="submit.php" method="post">

 

<p align="center"> </p>

<p align="center">Day: <select size="1" name="D1">

<option selected>01</option>

<option>02</option>

<option>03</option>

<option>04</option>

 

</select></p>

<p align="center">Month:  <select size="1" name="M1">

<option selected>01</option>

<option>02</option>

<option>03</option>

</select></p>

<p align="center">Year: <select size="1" name="Y1">

<option selected>2007</option>

<option>2008</option>

 

</select></p>

<p align="center">TimeFrom: <input type="Text" name="T1" size="4"></p>

<p align="center">TimeTo: <input type="Text" name="T2" size="4"></p>

<p align="center">Day: <select size="1" name="P1">

<option selected>Night.php</option>

<option>TTraining.php</option>

<option>Holiday.php</option>

<option>BankHoliday.php</option>

<option>ClosedAdverse.php</option>

<option>ClosedEmergency.php</option>

</select></p>

<br />

<input type="submit" name="submit" value="Submit" />

</form>

</body>

</html>

 

And here is the code from the submit.php

 

<?php

$d1 = $_POST['D1'];$m1 = $_POST['M1'];$y1 = $_POST['Y1'];$t1 = $_POST['T1'];$t2 = $_POST['T2'];$p1 = $_POST['P1'];

$filename = "dates.php";

$content = "$y1\n $m1\n $d1\n, $t1\n, $t2\n, $p1\n";

$fp = fopen($filename, "a");

$fw = fwrite( $fp, $content );

fclose( $fp );

?>

 

I also want to be able to delete a date from the file as well but for now if anyone could help me get the add format correct that would be great.

 

Thanks in advance

 

Alex

 

Link to comment
Share on other sites

Thanks

 

The dates.php file contains

 

// Special dates yyyymmdd,hhmm(start),hhmm(end),scriptName

20070720,1300,1630,Holiday.php

20070723,0815,1630,Holiday.php

20070724,0815,1630,Holiday.php

20070725,0815,1630,Holiday.php

20070726,0815,1630,Holiday.php

20070727,0815,1630,Holiday.php

20070730,0815,1630,Holiday.php

20070731,0815,1630,Holiday.php

20070801,0815,1630,Holiday.php

 

The only prob is its within an html page

i cant quite work out the what script needs to go ether side of

 

include("file.php");

 

Sorry im so new to this still learning

 

Thanks for your help its great

Link to comment
Share on other sites

<?php

$lines = file('dates.php');
$POSTDATE = $_POST["dateinput"];
// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line) {
    list($date, $timeone, $timetwo, $scriptname) = explode(",", $line);
if($date == $POSTDATE)
{
	echo "";
}
else
{
	echo "Date: ".$date."<br>";
	echo "Departure Time: ".$timeone."<br>"; // I assume 
	echo "Arrival Time: ".$timetwo."<br>";
	echo "Script: ".$scriptname."<br>"; // Dunno if you really need this, but what the hell
}
}

?>

Link to comment
Share on other sites

Fantastic that lists the file

 

I tried just pasting this in to the html page

 

<html>
<head>
<title>Send</title>
</head>
<body bgcolor="#000000" text="#FF0000" link="#FF0000" vlink="#FF0000">
<?php

$lines = file('dates.php');
$POSTDATE = $_POST["dateinput"];
// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line) {
    list($date, $timeone, $timetwo, $scriptname) = explode(",", $line);
if($date == $POSTDATE)
{
	echo "";
}
else
{
	echo "Date: ".$date."<br>";
	echo "Departure Time: ".$timeone."<br>"; // I assume 
	echo "Arrival Time: ".$timetwo."<br>";
	echo "Script: ".$scriptname."<br>"; // Dunno if you really need this, but what the hell
}
}

?> 

<form name="subscribe" action="submit.php" method="post">

<p align="center"> </p>
<p align="center">Day: <select size="1" name="D1">
<option selected>01</option>
<option>02</option>
<option>03</option>
<option>04</option>

 

i created a file called showdates.php with that script in and that lists it fine

 

now is there a way to diplayed this in the Changedates.html page

other than a link to it

 

Thanks

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.