TFD3 Posted July 27, 2007 Share Posted July 27, 2007 Quick question here.... Open this page: http://www.alabamaweather.org/beta/dispatch/test.php DONT type anything in the fields and just hit the refresh button a few times. You will see |||||| printed each time you hit refresh or load the URL. How can I get it to NOT do that? The script im using is below: <html> <head><title>911 Dispatch Logs</title></head> <body bgcolor="#002233" text=white> <H1>911 Dispatch Logs </H1> <?php // This is a form with "sticky" fields ..... ?> <form method=post> <TABLE BORDER="0" CELLPADDING="2" CELLSPACING="2" WIDTH="50%"> <TR> <TD>Department:</TD> <TD><select name=one> <?php $compass = array ("Center Point","Birmingham","Trussville","Fultondale") ; foreach ($compass as $possibility) { echo ("<option"); if ($HTTP_POST_VARS["one"] == $possibility) echo (" selected"); echo (">$possibility"); } ?></select></TD> </TR> <TR> <TD>Received:</TD> <TD><input name=two size=60 maxlength=100 value="<?php date_default_timezone_set('UTC'); echo date(DATE_RFC822);?>"<?php echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["two"]))); ?>" size=15></TD> </TR> <TR> <TD>Type of Call:</TD> <TD><input name=three size=60 maxlength=100 value="<?php echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["three"]))); ?>" size=15></TD> </TR> <TR> <TD>Location:</TD> <TD><input name=four size=60 maxlength=100 value="<?php echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["four"]))); ?>" size=15></TD> </TR> <TR> <TD>Unit(s):</TD> <TD><input name=five size=60 maxlength=100 value="<?php echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["five"]))); ?>" size=15></TD> </TR> <TR> <TD>Details:</TD> <TD><input name=six size=60 maxlength=100 value="<?php echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["six"]))); ?>" size=15></TD> </TR> </TABLE> </select> <input type="Submit" value="Submit"> <input type="Reset" value="Clear"> </form> <?php // Save all the fields on any previous form to a file $fh = fopen("../data","a"); fputs($fh, $HTTP_POST_VARS["one"]." | ". $HTTP_POST_VARS["two"]." | ". $HTTP_POST_VARS["three"]." | ". $HTTP_POST_VARS["four"]." | ". $HTTP_POST_VARS["five"]." | ". $HTTP_POST_VARS["six"]." | ". "\n"); fclose($fh); // Echo the file contents onto the end of the form ?> <FONT style="BACKGROUND-COLOR: #808080" COLOR=white><b> <?php $stuff = implode("",file("../data")); echo (nl2br(htmlspecialchars(stripslashes($stuff)))); ?></b> </FONT> </body> </html> I think it needs just an if or elseif statement(s) but I dont know where to place it at. Any help is greatly appreciated Thanks, Kenny Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 27, 2007 Share Posted July 27, 2007 Well, you only want to be doing this part of your code: <?php // Save all the fields on any previous form to a file $fh = fopen("../data","a"); fputs($fh, $HTTP_POST_VARS["one"]." | ". $HTTP_POST_VARS["two"]." | ". $HTTP_POST_VARS["three"]." | ". $HTTP_POST_VARS["four"]." | ". $HTTP_POST_VARS["five"]." | ". $HTTP_POST_VARS["six"]." | ". "\n"); fclose($fh); // Echo the file contents onto the end of the form ?> If the submit button has been clicked. Try: <html> <head><title>911 Dispatch Logs</title></head> <body bgcolor="#002233" text=white> <H1>911 Dispatch Logs </H1> <?php // This is a form with "sticky" fields ..... ?> <form method=post> <TABLE BORDER="0" CELLPADDING="2" CELLSPACING="2" WIDTH="50%"> <TR> <TD>Department:</TD> <TD><select name=one> <?php $compass = array ("Center Point","Birmingham","Trussville","Fultondale") ; foreach ($compass as $possibility) { echo ("<option"); if ($HTTP_POST_VARS["one"] == $possibility) echo (" selected"); echo (">$possibility"); } ?></select></TD> </TR> <TR> <TD>Received:</TD> <TD><input name=two size=60 maxlength=100 value="<?php date_default_timezone_set('UTC'); echo date(DATE_RFC822);?>"<?php echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["two"]))); ?>" size=15></TD> </TR> <TR> <TD>Type of Call:</TD> <TD><input name=three size=60 maxlength=100 value="<?php echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["three"]))); ?>" size=15></TD> </TR> <TR> <TD>Location:</TD> <TD><input name=four size=60 maxlength=100 value="<?php echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["four"]))); ?>" size=15></TD> </TR> <TR> <TD>Unit(s):</TD> <TD><input name=five size=60 maxlength=100 value="<?php echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["five"]))); ?>" size=15></TD> </TR> <TR> <TD>Details:</TD> <TD><input name=six size=60 maxlength=100 value="<?php echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["six"]))); ?>" size=15></TD> </TR> </TABLE> </select> <input type="Submit" value="Submit" name="submit"> <input type="Reset" value="Clear"> </form> <?php // Save all the fields on any previous form to a file if(isset($HTTP_POST_VARS['submit'])){ $fh = fopen("../data","a"); fputs($fh, $HTTP_POST_VARS["one"]." | ". $HTTP_POST_VARS["two"]." | ". $HTTP_POST_VARS["three"]." | ". $HTTP_POST_VARS["four"]." | ". $HTTP_POST_VARS["five"]." | ". $HTTP_POST_VARS["six"]." | ". "\n"); fclose($fh); } // Echo the file contents onto the end of the form ?> <FONT style="BACKGROUND-COLOR: #808080" COLOR=white><b> <?php $stuff = implode("",file("../data")); echo (nl2br(htmlspecialchars(stripslashes($stuff)))); ?></b> </FONT> </body> </html> Note the fact that i added a name to your submit button. You'll need that for php to check if it the form has been submitted. If you're running a version of php greater than 4.1, consider changing $HTTP_POST_VARS to $_POST. Thats the new version. Quote Link to comment Share on other sites More sharing options...
mpharo Posted July 27, 2007 Share Posted July 27, 2007 Is there a reason why your using a flat file instead of a database? I am assuming you want something like this... <html> <head><title>911 Dispatch Logs</title></head> <body bgcolor="#002233" text=white> <H1>911 Dispatch Logs </H1> <?php // This is a form with "sticky" fields ..... ?> <form method=post> <input type="hidden" name="posted" value="true"> <TABLE BORDER="0" CELLPADDING="2" CELLSPACING="2" WIDTH="50%"> <TR> <TD>Department:</TD> <TD><select name=one> <?php $compass = array ("Center Point","Birmingham","Trussville","Fultondale") ; foreach ($compass as $possibility) { echo ("<option"); if ($HTTP_POST_VARS["one"] == $possibility) echo (" selected"); echo (">$possibility"); } ?></select></TD> </TR> <TR> <TD>Received:</TD> <TD><input name=two size=60 maxlength=100 value="<?php date_default_timezone_set('UTC'); echo date(DATE_RFC822);?>"<?php echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["two"]))); ?>" size=15></TD> </TR> <TR> <TD>Type of Call:</TD> <TD><input name=three size=60 maxlength=100 value="<?php echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["three"]))); ?>" size=15></TD> </TR> <TR> <TD>Location:</TD> <TD><input name=four size=60 maxlength=100 value="<?php echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["four"]))); ?>" size=15></TD> </TR> <TR> <TD>Unit(s):</TD> <TD><input name=five size=60 maxlength=100 value="<?php echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["five"]))); ?>" size=15></TD> </TR> <TR> <TD>Details:</TD> <TD><input name=six size=60 maxlength=100 value="<?php echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["six"]))); ?>" size=15></TD> </TR> </TABLE> </select> <input type="Submit" value="Submit"> <input type="Reset" value="Clear"> </form> <?php // Save all the fields on any previous form to a file If ($_POST['posted']) { $fh = fopen("../data","a"); fputs($fh, $HTTP_POST_VARS["one"]." | ". $HTTP_POST_VARS["two"]." | ". $HTTP_POST_VARS["three"]." | ". $HTTP_POST_VARS["four"]." | ". $HTTP_POST_VARS["five"]." | ". $HTTP_POST_VARS["six"]." | ". "\n"); fclose($fh); } // Echo the file contents onto the end of the form ?> <FONT style="BACKGROUND-COLOR: #808080" COLOR=white><b> <?php $stuff = implode("",file("../data")); echo (nl2br(htmlspecialchars(stripslashes($stuff)))); ?></b> </FONT> </body> </html> Quote Link to comment Share on other sites More sharing options...
TFD3 Posted July 27, 2007 Author Share Posted July 27, 2007 Is there a reason why your using a flat file instead of a database? I am assuming you want something like this... <html> <head><title>911 Dispatch Logs</title></head> <body bgcolor="#002233" text=white> <H1>911 Dispatch Logs </H1> <?php // This is a form with "sticky" fields ..... ?> <form method=post> <input type="hidden" name="posted" value="true"> <TABLE BORDER="0" CELLPADDING="2" CELLSPACING="2" WIDTH="50%"> <TR> <TD>Department:</TD> <TD><select name=one> <?php $compass = array ("Center Point","Birmingham","Trussville","Fultondale") ; foreach ($compass as $possibility) { echo ("<option"); if ($HTTP_POST_VARS["one"] == $possibility) echo (" selected"); echo (">$possibility"); } ?></select></TD> </TR> <TR> <TD>Received:</TD> <TD><input name=two size=60 maxlength=100 value="<?php date_default_timezone_set('UTC'); echo date(DATE_RFC822);?>"<?php echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["two"]))); ?>" size=15></TD> </TR> <TR> <TD>Type of Call:</TD> <TD><input name=three size=60 maxlength=100 value="<?php echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["three"]))); ?>" size=15></TD> </TR> <TR> <TD>Location:</TD> <TD><input name=four size=60 maxlength=100 value="<?php echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["four"]))); ?>" size=15></TD> </TR> <TR> <TD>Unit(s):</TD> <TD><input name=five size=60 maxlength=100 value="<?php echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["five"]))); ?>" size=15></TD> </TR> <TR> <TD>Details:</TD> <TD><input name=six size=60 maxlength=100 value="<?php echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["six"]))); ?>" size=15></TD> </TR> </TABLE> </select> <input type="Submit" value="Submit"> <input type="Reset" value="Clear"> </form> <?php // Save all the fields on any previous form to a file If ($_POST['posted']) { $fh = fopen("../data","a"); fputs($fh, $HTTP_POST_VARS["one"]." | ". $HTTP_POST_VARS["two"]." | ". $HTTP_POST_VARS["three"]." | ". $HTTP_POST_VARS["four"]." | ". $HTTP_POST_VARS["five"]." | ". $HTTP_POST_VARS["six"]." | ". "\n"); fclose($fh); } // Echo the file contents onto the end of the form ?> <FONT style="BACKGROUND-COLOR: #808080" COLOR=white><b> <?php $stuff = implode("",file("../data")); echo (nl2br(htmlspecialchars(stripslashes($stuff)))); ?></b> </FONT> </body> </html> YES! Thats what I need however I found this error: When I go to change $fh = fopen("../data","a"); and $stuff = implode("",file("../data")); TO $fh = fopen("../data1","a"); and $stuff = implode("",file("../data1")); just changed the data to data1 so I can get a fresh blank page. I get this error: Warning: file(../data1) [function.file]: failed to open stream: No such file or directory in /home/alabamaw/public_html/beta/dispatch/test.php on line 90 Warning: implode() [function.implode]: Bad arguments. in /home/alabamaw/public_html/beta/dispatch/test.php on line 90 I used to be able to change those two lines and it worked, but now it does not. However this is what I need, now just to erase everything so I can start using it. Quote Link to comment Share on other sites More sharing options...
TFD3 Posted July 27, 2007 Author Share Posted July 27, 2007 Any idea Ben? I have the latest version of PHP so I went ahead and changed $HTTP_POST_VARS to $_POST. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 27, 2007 Share Posted July 27, 2007 Ok, can you post up the code you are using now, just so we can see exactly where you are at. As far as the error is concerned, its basically saying the file doesn't exist. Im a little confused as to what file you're trying to access anyway. Is it a text file? Shouldn't there be an extension for the file? Quote Link to comment Share on other sites More sharing options...
TFD3 Posted July 27, 2007 Author Share Posted July 27, 2007 This is the script: <html> <head><title>911 Dispatch Logs</title></head> <body bgcolor="#002233" text=white> <H1>911 Dispatch Logs </H1> <?php // This is a form with "sticky" fields ..... ?> <form method=post> <TABLE BORDER="0" CELLPADDING="2" CELLSPACING="2" WIDTH="50%"> <TR> <TD>Department:</TD> <TD><select name=one> <?php $compass = array ("Center Point","Birmingham","Trussville","Fultondale") ; foreach ($compass as $possibility) { echo ("<option"); if ($HTTP_POST["one"] == $possibility) echo (" selected"); echo (">$possibility"); } ?></select></TD> </TR> <TR> <TD>Received:</TD> <TD><input name=two size=60 maxlength=100 value="<?php date_default_timezone_set('UTC'); echo date(DATE_RFC822);?>"<?php echo (htmlspecialchars(stripslashes($HTTP_POST["two"]))); ?>" size=15></TD> </TR> <TR> <TD>Unit(s):</TD> <TD><input name=three size=60 maxlength=100 value="<?php echo (htmlspecialchars(stripslashes($HTTP_POST["three"]))); ?>" size=15></TD> </TR> <TR> <TD>Location:</TD> <TD><input name=four size=60 maxlength=100 value="<?php echo (htmlspecialchars(stripslashes($HTTP_POST["four"]))); ?>" size=15></TD> </TR> <TR> <TD>Type of Call:</TD> <TD><input name=five size=60 maxlength=100 value="<?php echo (htmlspecialchars(stripslashes($HTTP_POST["five"]))); ?>" size=15></TD> </TR> <TR> <TD>Details:</TD> <TD><input name=six size=60 maxlength=100 value="<?php echo (htmlspecialchars(stripslashes($HTTP_POST["six"]))); ?>" size=15></TD> </TR> </TABLE> </select> <input type="Submit" value="Submit" name="Submit"> <input type="Reset" value="Clear" name="Clear"> </form> <?php // Save all the fields on any previous form to a file if(isset($HTTP_POST['submit'])){ $fh = fopen("../data","a"); fputs($fh, $HTTP_POST["one"]." | ". $HTTP_POST["two"]." | ". $HTTP_POST["three"]." | ". $HTTP_POST["four"]." | ". $HTTP_POST["five"]." | ". $HTTP_POST["six"]." | ". "\n"); fclose($fh); } ?> <FONT style="BACKGROUND-COLOR: #808080" COLOR=white><b> <?php // Echo the file contents onto the end of the form $stuff = implode("",file("../data")); echo (nl2br(htmlspecialchars(stripslashes($stuff)))); ?></b> </FONT> </body> </html> The error is gone now b/c I fixed that my self using trial and error. Open this page: http://www.alabamaweather.org/beta/dispatch/test.php Type something in each field, click submit. The data now does not show up like before. Quote Link to comment Share on other sites More sharing options...
mpharo Posted July 27, 2007 Share Posted July 27, 2007 add an echo in your if statement and see if you get output, if you dont then your if statement isnt being validated. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 27, 2007 Share Posted July 27, 2007 Ah, i didn't mean use $HTTP_POST. Its just $_POST. Try: <html> <head><title>911 Dispatch Logs</title></head> <body bgcolor="#002233" text=white> <H1>911 Dispatch Logs </H1> <?php // This is a form with "sticky" fields ..... ?> <form method=post> <TABLE BORDER="0" CELLPADDING="2" CELLSPACING="2" WIDTH="50%"> <TR> <TD>Department:</TD> <TD><select name=one> <?php $compass = array ("Center Point","Birmingham","Trussville","Fultondale") ; foreach ($compass as $possibility) { echo ("<option"); if ($_POST["one"] == $possibility) echo (" selected"); echo (">$possibility"); } ?></select></TD> </TR> <TR> <TD>Received:</TD> <TD><input name=two size=60 maxlength=100 value="<?php date_default_timezone_set('UTC'); echo date(DATE_RFC822);?>"<?php echo (htmlspecialchars(stripslashes($_POST["two"]))); ?>" size=15></TD> </TR> <TR> <TD>Unit(s):</TD> <TD><input name=three size=60 maxlength=100 value="<?php echo (htmlspecialchars(stripslashes($_POST["three"]))); ?>" size=15></TD> </TR> <TR> <TD>Location:</TD> <TD><input name=four size=60 maxlength=100 value="<?php echo (htmlspecialchars(stripslashes($_POST["four"]))); ?>" size=15></TD> </TR> <TR> <TD>Type of Call:</TD> <TD><input name=five size=60 maxlength=100 value="<?php echo (htmlspecialchars(stripslashes($_POST["five"]))); ?>" size=15></TD> </TR> <TR> <TD>Details:</TD> <TD><input name=six size=60 maxlength=100 value="<?php echo (htmlspecialchars(stripslashes($_POST["six"]))); ?>" size=15></TD> </TR> </TABLE> </select> <input type="Submit" value="Submit" name="Submit"> <input type="Reset" value="Clear" name="Clear"> </form> <?php // Save all the fields on any previous form to a file if(isset($_POST['Submit'])){ $fh = fopen("../data","a"); fputs($fh, $_POST["one"]." | ". $_POST["two"]." | ". $_POST["three"]." | ". $_POST["four"]." | ". $_POST["five"]." | ". $_POST["six"]." | ". "\n"); fclose($fh); } ?> <FONT style="BACKGROUND-COLOR: #808080" COLOR=white><b> <?php // Echo the file contents onto the end of the form $stuff = implode("",file("../data")); echo (nl2br(htmlspecialchars(stripslashes($stuff)))); ?></b> </FONT> </body> </html> Also notice i modified this line: if(isset($_POST['Submit'])){ The keys of arrays are case sensitive, and the name given to the HTML tag was with a capital S, so this needs a capital S too. Quote Link to comment Share on other sites More sharing options...
TFD3 Posted July 27, 2007 Author Share Posted July 27, 2007 You da man Bed That worked, thank you! http://www.alabamaweather.org/beta/dispatch/test.php Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 27, 2007 Share Posted July 27, 2007 No problem. I noticed it was working. That stray 'test' data was me Quote Link to comment Share on other sites More sharing options...
TFD3 Posted July 27, 2007 Author Share Posted July 27, 2007 No problem. I noticed it was working. That stray 'test' data was me I dont see your test but ok thanks! Quote Link to comment Share on other sites More sharing options...
TFD3 Posted July 27, 2007 Author Share Posted July 27, 2007 Now, later on im going to attempt to make the highlighted text a different color depending on which department I choose. If this is going to be hard or will take some time then just tell me and ill skip it. But I probably will end up needing some help Thank you guys! 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.