turtleman8605 Posted May 23, 2007 Share Posted May 23, 2007 I am trying to write a script for an interactive calendar. What I want to do is to click on a date, and have a box appear with a form to add an event to that date in the calendar. The box is a hidden div that becomes visible when a date is clicked (using javascript) and the form is doing what its supposed to do. Now what I am having trouble with is appending the calendar to show the new date. I was trying to use fopen and then str_replace but since the page is being viewed the file won't open. Quote Link to comment https://forums.phpfreaks.com/topic/52610-trying-to-write-to-a-web-page/ Share on other sites More sharing options...
georg Posted May 23, 2007 Share Posted May 23, 2007 I Think, it's time to show us some code... Quote Link to comment https://forums.phpfreaks.com/topic/52610-trying-to-write-to-a-web-page/#findComment-259610 Share on other sites More sharing options...
MasterACE14 Posted May 23, 2007 Share Posted May 23, 2007 agreed Quote Link to comment https://forums.phpfreaks.com/topic/52610-trying-to-write-to-a-web-page/#findComment-259611 Share on other sites More sharing options...
turtleman8605 Posted May 23, 2007 Author Share Posted May 23, 2007 ok here's the code: function process_form(){ echo ('<script type="text/javascript">initImage()</script>'); $file = 'calendar.php'; $currentString = '<td class="num"><a href="#" onClick="initImage()">18</a></td>'; $newString = '<td class="pop">26 <p class="event"> <a href="#"><b>'. $_POST['title'] .'</b> <span class="ev_pop"> <span><strong>men in drag</strong> Event</span> <p>'. $_POST['event'] .'</p> <b>Date:</b> '. $_POST['date'] .'<br /> <b>Time:</b> '. $_POST['time'] .'<br /> <b>Place:</b> '. $_POST['place'] .'<br /> <b>Admission:</b> '. $_POST['admis'] .' </span></a> </p> </td>'; $lineAppend = str_replace( $currentString, $newString, $currentString ); $fh = fopen($file, 'a') or die("Cannot open file"); fwrite ( $fh, $lineAppend ); fclose ($fh); And here's the problems: 1) when I execute it on the page, it doesn't up where the existing code is, but (as append mode does), tags it on the end of the page. 2) in order for it to work like this, I have to give public write permissions on my server. Quote Link to comment https://forums.phpfreaks.com/topic/52610-trying-to-write-to-a-web-page/#findComment-259617 Share on other sites More sharing options...
georg Posted May 23, 2007 Share Posted May 23, 2007 I don't understand, what you do here: $lineAppend = str_replace( $currentString, $newString, $currentString ); You simply replace an existing string with another? wouldn't be $lineAppend = $newString; simpler? Why do you write another file? I think It would be much simpler to write all in one file to generate the calendar... Quote Link to comment https://forums.phpfreaks.com/topic/52610-trying-to-write-to-a-web-page/#findComment-259620 Share on other sites More sharing options...
turtleman8605 Posted May 23, 2007 Author Share Posted May 23, 2007 the reason I am using str_replace is because I am trying to get this section of code to appear in a certain date on the calendar represented by a cell in a table. also, I'm not using another file, it's all in one. I just need to figure out how to get the input text to show up where its supposed to go instead of at the end of the page. Quote Link to comment https://forums.phpfreaks.com/topic/52610-trying-to-write-to-a-web-page/#findComment-259624 Share on other sites More sharing options...
dsaba Posted May 23, 2007 Share Posted May 23, 2007 are you saying that you're trying to append something or write something in a file in the middle of the file? consider using file_get_contents('fileurl'); to get the contents of the file instead of fopen then use regex to replace or find a certain string, and replace it with something else, in a certain spot Quote Link to comment https://forums.phpfreaks.com/topic/52610-trying-to-write-to-a-web-page/#findComment-259636 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.