4 Replies - 860 Views - Last Post: 08 June 2012 - 05:29 AM Rate Topic: -----

#1 Frankma5   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 46
  • Joined: 07-January 12

php not working

Posted 05 June 2012 - 09:16 AM

hey i am not sure if this should be in the host site part or in the php help but i am having some problems with my php script. it works fine on my localhost but when i put it on my free host it does not work . my free host is with 000webhost.com. i just get a 404 page and it does not write to a .txt file the info i want.

i don't know if i am say this right :( so maybe it is better if you take a look at the site and the code http://mulvifrank.site50.net/

here is the php (i am new to php and still learning so any tip will be great :) )
<html>
<head>
		<title> :)/></title>
		
		<style type="text/css">
			body{background-image:url(rainbow.jpg)}
			h1{color:red;text-align:center;}
			h2{color:red;text-align:center;}
			h3{color:red;}
		</style>
</head>
<body>
		<h1>This page is being worked on </h1>
		

</body>
<h2>
<?php

$time = time();
$real_time = date('H:i:s', $time);
$mod_time = date('d M Y @ H:i:s', strtotime('+5 hour' ));

echo 'The Date and Time you visted at  '.$mod_time ;

?>
<?php
$name = "";
$comment= "";
if (isset($_POST['name'])&&isset($_POST['comment'])&& !empty($_POST['name'])&& !empty($_POST['comment'])){

$name = $_POST['name'];
$comment = $_POST['comment'];
}


?>
</h2>

		<form action="website.php" method="POST">
		<h3>Name... : <input type="text" name="name"></h3><br>
		<h3>Comment : <textarea name="comment" rows="10" cols="40"></textarea><br>
		<input type="submit" value="Submit">
		
		</form>
			<?php
				$handle =fopen('comments.txt','a');
				
				fwrite($handle,$name ."\r\n"."\r\n");
				fwrite($handle,$comment ."\r\n"."\r\n");
				
				fclose($handle);
			?>



thank you very much :D

Is This A Good Question/Topic? 0
  • +

Replies To: php not working

#2 Kiakime   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 24
  • Joined: 27-February 12

Re: php not working

Posted 05 June 2012 - 09:57 AM

I get a 404 error when I go to "http://mulvifrank.site50.net/website.php". Just making sure -- you do have that page in the same directory for your form to submit to?

This post has been edited by Kiakime: 05 June 2012 - 09:59 AM

Was This Post Helpful? 0
  • +
  • -

#3 Kiakime   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 24
  • Joined: 27-February 12

Re: php not working

Posted 05 June 2012 - 10:20 AM

Okay, I tested it out; I'm pretty sure your form is submitting to a page that doesn't exist, and I assume that page was supposed to redirect back to this one and pass the $_POST variables. I can't speak for the validity of that, but it works fine on the same host if you collect the data on the "website.php" page instead and write it to the txt file.

On the first page:

<html>
<head>
		<title> :)/></title>
		
		<style type="text/css">
			body{background-image:url(rainbow.jpg)}
			h1{color:red;text-align:center;}
			h2{color:red;text-align:center;}
			h3{color:red;}
		</style>
</head>
<body>
		<h1>This page is being worked on </h1>
		

</body>
<h2>
<?php

$time = time();
$real_time = date('H:i:s', $time);
$mod_time = date('d M Y @ H:i:s', strtotime('+5 hour' ));

echo 'The Date and Time you visted at  '.$mod_time ;

?>
</h2>

		<form action="website.php" method="POST">
		<h3>Name... : <input type="text" name="name"></h3><br>
		<h3>Comment : <textarea name="comment" rows="10" cols="40"></textarea><br>
		<input type="submit" value="Submit">
		
		</form>



On the second page:

<html>
<head>
		<title> :)/></title>
		
		<style type="text/css">
			body{background-image:url(rainbow.jpg)}
			h1{color:red;text-align:center;}
			h2{color:red;text-align:center;}
			h3{color:red;}
		</style>
</head>
<body>
		<h1>This page is being worked on </h1>
		

</body>
<h2>
<?php

$time = time();
$real_time = date('H:i:s', $time);
$mod_time = date('d M Y @ H:i:s', strtotime('+5 hour' ));

echo 'The Date and Time you visted at  '.$mod_time ;

$name = "";
$comment= "";

if (isset($_POST['name'])&&isset($_POST['comment'])&& !empty($_POST['name'])&& !empty($_POST['comment'])){

$name = $_POST['name'];
$comment = $_POST['comment'];

				$handle =fopen('comments.txt','a');
				
				fwrite($handle,$name ."\r\n"."\r\n");
				fwrite($handle,$comment ."\r\n"."\r\n");
				
				fclose($handle);
}
			?>



Then code in your own redirect back to the original page.

This post has been edited by Kiakime: 05 June 2012 - 10:21 AM

Was This Post Helpful? 1
  • +
  • -

#4 BenignDesign   User is offline

  • holy shitin shishkebobs
  • member icon




Reputation: 8154
  • View blog
  • Posts: 12,520
  • Joined: 28-September 07

Re: php not working

Posted 05 June 2012 - 01:15 PM

Can you show us the code for the file "website.php"?
Was This Post Helpful? 0
  • +
  • -

#5 Frankma5   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 46
  • Joined: 07-January 12

Re: php not working

Posted 08 June 2012 - 05:29 AM

i have fixed it thanks Kiakime you helped alot man :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1