g7psj Posted July 11, 2007 Share Posted July 11, 2007 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 Quote Link to comment Share on other sites More sharing options...
Yesideez Posted July 11, 2007 Share Posted July 11, 2007 $content = "$y1,$m1,$d1,$t1,$t2,$p1\n"; You're adding new lines in the middle. Quote Link to comment Share on other sites More sharing options...
g7psj Posted July 11, 2007 Author Share Posted July 11, 2007 Fantastic It works Ok next question is there a way i can display the content of the dates.php file in the html page and is there a way i can remove a line from it Thank Yesideez Quote Link to comment Share on other sites More sharing options...
Yesideez Posted July 11, 2007 Share Posted July 11, 2007 What does dates.php contain? You can include php files inside others by using something like this: include("file.php"); Quote Link to comment Share on other sites More sharing options...
g7psj Posted July 11, 2007 Author Share Posted July 11, 2007 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 Quote Link to comment Share on other sites More sharing options...
OLG Posted July 11, 2007 Share Posted July 11, 2007 What line are you trying to remove? Quote Link to comment Share on other sites More sharing options...
g7psj Posted July 11, 2007 Author Share Posted July 11, 2007 Hi OLG I want to enter a date into a form field and remove that line from the dates list Thanks Alex Quote Link to comment Share on other sites More sharing options...
OLG Posted July 11, 2007 Share Posted July 11, 2007 <?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 } } ?> Quote Link to comment Share on other sites More sharing options...
g7psj Posted July 11, 2007 Author Share Posted July 11, 2007 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 Quote Link to comment Share on other sites More sharing options...
Yesideez Posted July 11, 2007 Share Posted July 11, 2007 You can change the changedates.html to changedates.php and include() it in - is that what you're after? Quote Link to comment Share on other sites More sharing options...
g7psj Posted July 11, 2007 Author Share Posted July 11, 2007 Bingo Thanks all you have been a great help mutch appreciated. Just got the deleteing bit to sort now getting the hang of this slowly lol Regards Alex Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.