PHP Code Help

A

Anonymous

Guest
Hi I am very new to PHP but have managed to put togther a page that interacts with text files for regional leaders of my club to be able to edit there details.

The problem i am having is one of the files contains a HTML link

e.g. <A HREF=" etc etc

and when it is loaded into the form is mucks up the form.

I have been told I need to use htmlspecialchars????


This is the code if anybody can help it will be much appreciated

Cheers Baz


Code:
<h1 align="center"><font color="#000099"><a name="top"></a> 
<?php 
include 'regionalname.txt'; 
?> Update Page 
</font></h1> 
<p align="center">Only 
<?php 
include 'rlname.txt'; 
?> 
Has Permission To Update This Page 
<form method=post> 
<input type="hidden" value="<?php $tmp=($_POST["file"])?$_POST["file"]:$_GET["file"]; echo $tmp;?>" name="file"> 
<select name ="file"> 
<option value=""> Please Choose From Bellow 
<option value="regionalname.txt"> Region Name 
<option value="rlname.txt"> Regional Leaders Name 
<option value="forumid.txt"> Forum ID 
<option value="meetdate.txt"> Meet Date 
<option value="nxtmeet.txt"> Next Meet 
<option value="forumid.txt"> Forum ID 
<option value="map.txt"> Map to meet location 
<option value="meetcomments.txt"> Meet Comments 
<option value="website.txt"> Regional Website Link 
<option value="contact.txt"> Contact Details 
</select> 
<input value="Open File" type=submit><hr> 
<p> 
<?php 
if ($_POST["submit"]=="submit") { // begin if statement 
if (@fwrite(@fopen($_POST["write"],"wb"), $_POST["filetext"])) { 
echo "File write successful"; 
} else { 
echo "File write unsuccessful"; 
} 
} else { //begin else block ?> 
<input name="filetext" type="text" value=" 
<?php echo @fread(@fopen($tmp,"r"), @filesize($tmp));?> 
" size="90"> 
<p> Please Confirm The File To Be Updated 
<select name ="write"> 
<option value=""> Please Choose From Bellow 
<option value="regionalname.txt"> Region Name 
<option value="rlname.txt"> Regional Leaders Name 
<option value="forumid.txt"> Forum ID 
<option value="meetdate.txt"> Meet Date 
<option value="nxtmeet.txt"> Next Meet 
<option value="map.txt"> Map to meet location 
<option value="meetcomments.txt"> Meet Comments 
<option value="website.txt"> Regional Website Link 
<option value="contact.txt"> Contact Details 
</select> 
<p> 
<input name=submit value=submit type=submit> 
<?php } //end if statement?> 
</form> 

<p align="center"> </p>
 
bazpug said:
I have been told I need to use htmlspecialchars????

So what happened when you tried to use htmlspecialchars()? Did it solve your problem?
 
Unfortunaltley I tried it but incorrectly I dont know how to use it. Sounds like it is what i need from what I have read but I can't get it to work with my code :?
 
Using a function that accepts one string parameter and returns a string is very basic PHP. You need to learn how to do these things yourself. Go buy a good PHP book, or find a good tutorial.
 
I fully intend too mate, I want to know it inside out. I am just nearly ready to launch a huge website and I need this function working. At this moment in time I thought somebody may be able to help me, its not like I am asking people to write the whole thing for me :?
 
Code:
<?
$a = "A string with some <em>HTML</em> in it.";
$a = htmlspecialchars($a);

echo $a;
?>
 
Have tried using it in several pages and cant get it to work

A picture to show you whats happening

error.gif


Baz
 
<input name="filetext" type="text" value="
<?php echo @fread(@fopen($tmp,"r"), @filesize($tmp));?>
" size="90">

when php parse this then from php parsed output it is closing the
<input ....... tag with > char and browser close that input and the rest of the input data is outside the field...
try this

<?php echo " ' ".@fread(@fopen($tmp,"r"), @filesize($tmp)) ." ' " ;?> ..
hope it solves the problem..
 
Back
Top