Hello. New to php and need some help!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
AshrakTheWhite
Forum Commoner
Posts: 69
Joined: Thu Feb 02, 2006 6:47 am

Hello. New to php and need some help!

Post by AshrakTheWhite »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hi im new :p

Iv got a little thing i want to do. I want to input a few numbers and submit them, then i want them to be written out on a webpage after which i want to store them in a serverside text file. Sofar i have this code:

Code: Select all

<html>
<head></head>
<body>
<pre>
<?php
$arr = file("/var/www/test.txt");
foreach ($arr as $line) {
  print $line;
}
?>
</pre>

<?php
// retrieve form data
$input1 = $_POST['msg1'];
$input2 = $_POST['msg2'];
$input3 = $_POST['msg3'];
$input4 = $_POST['msg4'];
$iive = $input1-$input2;
$filename = '/var/www/test.txt';
$somecontent = '';
$kuupaev = date("l dS \of F Y h:i:s A");
// use it

$somecontent = "$kuupaev";
$somecontent += "'Sisse tuli: ' + $input1 + '<br>' ";
$somecontent += "'Välja läks: ' + $input2 + '<br>' ";
$somecontent += "'Iiive: ' + $iive + '<br>' ";
$somecontent += "'Katkiseid Arvuteid: ' + $input3 + '<br>' ";
$somecontent += "'Korras Arvuteid: ' + $input4 + '<br>' ";

echo $somecontent;

if (is_writable($filename)) {
   if (!$handle = fopen($filename, 'a')) {
         echo "Cannot open file ($filename)";
         exit;
   }
   if (fwrite($handle, $somecontent) === FALSE) {
       echo "Cannot write to file ($filename)";
       exit;
   }
   echo "Success.";
   fclose($handle);
} else {
   echo "The file $filename is not writable";
}

?>
<br>
</body>
</html>

This might be horribly wrong but as i said im new!

Any help accepted with open hands :)


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

$somecontent = "$kuupaev";
$somecontent  = "'Sisse tuli: '   $input1   '<br>' ";
$somecontent  = "'Välja läks: '   $input2   '<br>' ";
$somecontent  = "'Iiive: '   $iive   '<br>' ";
$somecontent  = "'Katkiseid Arvuteid: '   $input3   '<br>' ";
$somecontent  = "'Korras Arvuteid: '   $input4   '<br>' ";
should be

Code: Select all

$somecontent = $kuupaev;
$somecontent .= 'Sisse tuli: ' . $input1 . '<br>';
$somecontent .= 'Välja läks: ' . $input2 . '<br>';
$somecontent .= 'Iiive: ' . $iive . '<br>';
$somecontent .= 'Katkiseid Arvuteid: ' . $input3 . '<br>';
$somecontent .= 'Korras Arvuteid: ' . $input4 . '<br>';
unless I'm mistaken with what you're trying to do..
AshrakTheWhite
Forum Commoner
Posts: 69
Joined: Thu Feb 02, 2006 6:47 am

Post by AshrakTheWhite »

Nevermind a slight oversight on my part! Thanx for the help!
Post Reply