/    Sign up×
Community /Pin to ProfileBookmark

Problem executing file_get_contents() in a form

I’ve set up a form where you enter in a system message and then after submitting the form, it is suppose to display that message. But, in my case, it just goes to a blank page. There aren’t any error messages, it’s just blank.

Form code:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>

<html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en” lang=”en”>
<head>
<title>Application Level Data</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />

</head>

<body>
<?php
if($_SERVER[‘REQUEST_METHOD’] != ‘POST’)
{
?>
<form action=”system_message.php” method=”POST”>
<h2 align=”center”>Application Level Data</h2>

<br />
<div>
<p>System Message:<input type=”text” name=”message” size=”50″></p>
</div>
<br />
<div><input type=”submit” name=”submit” value=”Submit” /></div>
<br />
<div>
<input type=”reset” name=”Reset” value=”Start Over” />
</div>

</form>

<?php
}
else
{
file_put_contents(‘message.txt’, $_POST[‘message’]);
}

?>
</body>
</html>

PHP file:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>

<html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en” lang=”en”>
<head>
<title>Application Level Data</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />

</head>

<body>
<?php
print file_get_contents(“message.txt”);
?>
</body>
</html>

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@VodkaProDrinkerMar 01.2009 — first, try to locate the problem.

try to view the message before she get into the file_put_contents() function. ( - if it's he does not show the message, it's a sign that he isn't revise the message from the form)

try to view the message.txt file right after you put the message into him. ( - if it's does not view the message, it's a sign that you probably reading the file wrong.

any way, a few general suggestions:

- use "id" as well as you use "name" (html property)

- try to redesign your code. try use more structural in your code.

- use less breaks <?php ?> and more echos.
Copy linkTweet thisAlerts:
@chazzyMar 01.2009 — add
[code=php]<?php
error_reporting(E_ALL);
?>[/code]

Somewhere to see the error.
×

Success!

Help @MichiKen spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...