This is a discussion on php and forms within the alt.comp.lang.php forums, part of the PHP Programming Forums category; hi can PHP be used to do CGI functions on say forms, I know it can use databases like mysql. ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
*** john townsley wrote/escribió (Mon, 14 Jun 2004 21:07:04 +1000):
> can PHP be used to do CGI functions on say forms, I know it can use > databases like mysql. > for eg a simple form which asks for users name and comments , the details to > be stored on a simple text file Not sure of what you mean. You don't need to mix up CGI and PHP to write a guestbook. You can write a CGI-only or a PHP-only solution. -- -- -- Álvaro G. Vicario - Burgos, Spain -- |
|
|||
|
On Mon, 14 Jun 2004 21:07:04 +1000 (more or less), "john townsley"
<johntownsley@optusnet.com.au> wrote: >hi > >can PHP be used to do CGI functions on say forms, I know it can use >databases like mysql. >for eg a simple form which asks for users name and comments , the details to >be stored on a simple text file > <? /* records form response to file form contains two fields, "name" and "comments". */ if (!(isset($_POST[submit]))): { $fname = "/path/to/file.txt"; $file = fopen($fname,"a+") or die("file open failed"); $data=array($_POST['name'],$_POST['comments']); $content=makeCSV($data) $content.="\n"; fwrite($file,$content) or die("fwrite failed"); fclose($file); } /*--- makeCSV Given an array of string data, returns a single string with each element quoted and separated by commas ---*/ function makeCSV($data) { $sep = '","'; if(!is_array($data)) { return ''; } $ret = ''; foreach($data as $record) { $ret = $ret.$sep.$record; } // strip off leading sep and add closing quote $ret = substr($ret,2).'"'; return $ret; } ?> |