Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with 'edit this page' script

Status
Not open for further replies.

JamesGecko

Programmer
Dec 18, 2004
1
US
I have this simple 'edit this page' script that won't work. I don't know why. I have tested the first two modules of code and they seem to work without any problem.


<?php
print "<h2>Edit this page</h2><p>";
//load up the text
$fp = fopen("./pinboard.txt", "r");
$content = fread($fp, filesize('./pinboard.txt'));
fclose($fp);
print "<pre>$content</pre><p>";
if (isset($_POST[content])) {
//write back the text
$fp = fopen("./pinboard.txt","w");
fwrite($fp, $_POST[content]);
fclose($fp);
}
//get a text box up for input
<form action=$_SERVER['PHP_SELF'] method=POST>
print "<textarea rows=5 cols=20 name=content wrap=physical>Text</textarea><br>";
<input type=submit>
</form>
?>
 
<?php
print "<h2>Edit this page</h2><p>";
//load up the text
$fp = fopen("./pinboard.txt", "r");
$content = fread($fp, filesize('./pinboard.txt'));
fclose($fp);
print "<pre>$content</pre><p>";
if (isset($_POST[content])) {
//write back the text
$fp = fopen("./pinboard.txt","w");
fwrite($fp, $_POST[content]);
fclose($fp);
}
//get a text box up for input
<form action=$_SERVER['PHP_SELF'] method=POST>
Code:
 print "<textarea rows=5 cols=20 name=content wrap=physical>$_POST['content']</textarea><br>";
<input type=submit> 
</form>
?>
 
oops >_>

Code:
<?php
print "<h2>Edit this page</h2><p>";
//load up the text
$fp = fopen("./pinboard.txt", "r");
$content = fread($fp, filesize('./pinboard.txt'));
fclose($fp);
print "<pre>$content</pre><p>";
if (isset($_POST['content'])) {
//write back the text
$fp = fopen("./pinboard.txt","w");
fwrite($fp, $_POST['content']);
fclose($fp);
}
//get a text box up for input
<form action=$_SERVER['PHP_SELF'] method=POST>
print "<textarea rows=5 cols=20 name=content wrap=physical>$_POST['content'];</textarea><br>";
<input type=submit>
</form>
?>
 
okay, lets have a look at your code here:
<form action=$_SERVER['PHP_SELF'] method=POST>
print "<textarea rows=5 cols=20 name=content wrap=physical>$_POST['content'];</textarea><br>";
<input type=submit>
</form>

Why do you have the semicolon after the post variable?
The semicolon emplies that it is at the end of something which is to be executed.

if (something) {
do(something);
}

You have two ways of echoing a variable inside a form:
Code:
<form action=$_SERVER['PHP_SELF'] method=POST>
echo "<textarea rows=\"5\" cols=\"20\" name=\"content\" id=\"content\" wrap=\"physical\">{$_POST['content']}</textarea><br />";
<input type=submit>
</form>

Or:
Code:
<form action=$_SERVER['PHP_SELF'] method=POST>
<textarea rows="5" cols="20" name="content" id="content" wrap="physical"><?=$_POST['content']?></textarea><br />
<input type=submit>
</form>

ps. I might have given you some typo's here, since it's early in the morning.

Olav Alexander Mjelde
Admin & Webmaster
 
Code:
<form action=$_SERVER['PHP_SELF'] method=POST>
<textarea rows="5" cols="20" name="content" id="content" wrap="physical"><?=$_POST['content']?></textarea><br />
<input type=submit>
</form>
Wouldn't that have to be
Code:
<form action=[red]<?=[/red]$_SERVER['PHP_SELF'][red]?>[/red] method=POST>
<textarea rows="5" cols="20" name="content" id="content" wrap="physical"><?=$_POST['content']?></textarea><br />
<input type=submit>
</form>
Also, you should put quotes around your html attributes.

--Chessbot

There is a level of Hell reserved for probability theorists in which every monkey that types on a typewriter produces a Shakespearean sonnet.
 
ah, I didnt see that he had the PHP_SELF there.

you can cheat that one, by just putting ?foo in the action, so it will submit to self.

Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top