Code Help Please

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
bazpug
Forum Newbie
Posts: 8
Joined: Fri Oct 17, 2003 2:21 am

Code Help Please

Post by bazpug »

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:

Code: Select all

<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>
[mod_edit:

Code: Select all

tag added][/size] 

Here is a pic to show you whats happening

[img]http://www.pgac.peugeot-gti.net/error.gif[/img]
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

<?php echo @fread(@fopen($tmp,"r"), @filesize($tmp));?>
this is the code that outputs the file content.
Since you obviously want it all in one line of code ( ;-) ) try

Code: Select all

<?php echo htmlentities(@fread(@fopen($tmp,"r"), @filesize($tmp)));?>
bazpug
Forum Newbie
Posts: 8
Joined: Fri Oct 17, 2003 2:21 am

Post by bazpug »

Can I just say




I LOVE YOU !!!!!!!

Sorry I have been trying to get this working for ages, this is the 3rd forum I have tried and it now works. Cheers mate your help is very appreciated !

Can i just say im not gay :D
bazpug
Forum Newbie
Posts: 8
Joined: Fri Oct 17, 2003 2:21 am

Post by bazpug »

DOH!

:cry:

It now doesn't muck up the form but the link instead

it turns

<a href="http://www.pgacwilts.co.uk" target="_blank">www.pgacwilts.co.uk</a>

into

<a href=\"http://www.pgacwilts.co.uk\" target=\"_blank\">www.pgacwilts.co.uk</a>

HELP!!!!!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

strange, must be magic_quote-month this month 8O
what does

Code: Select all

<?php phpinfo();?>
tell you about magic_quotes_gpc , magic_quotes_runtime and magic_quotes_sybase?

anyway you can take a look at http://php.net/stripslashes. The function is for removing escape-slashes.
bazpug
Forum Newbie
Posts: 8
Joined: Fri Oct 17, 2003 2:21 am

Post by bazpug »

Tried using stripslashes doesnt sort it.

What you mean by

<?php phpinfo();?> ?

The page in question is at

http://www.pgac.peugeot-gti.net/regional/pgacwilts/

If you hover over the click here and look in your status bar you will see the website address is wrong.

The code for that section

<td width="42%"><p>Regional Leaders</p></td>
<td width="58%"><p>
<?php
include 'content/rlname.txt';
?>
</p></td>
</tr>
<tr>
<td><p>Regional Leaders Forum ID</p></td>
<td><p>
<?php
include 'content/forumid.txt';
?>
</p></td>
</tr>
<tr>
<td><p>Meet Dates</p></td>
<td><p>
<?php
include 'content/meetdate.txt';
?>
</p></td>
</tr>
<tr>
<td><p>Next Meet</p></td>
<td><p>
<?php
include 'content/nxtmeet.txt';
?>
</p></td>
</tr>
<tr>
<td><p>Meet Location</p></td>
<td><p>
<?php
include 'content/meetlocation.txt';
?>
</p></td>
</tr>
<tr>
<td><p>Map To Meet Location</p></td>
<td><p>
<?php
include 'content/map.txt';
?>
</p></td>
</tr>
<tr>
<td> <p>Meet Comments</p></td>
<td> <p>
<?php
include 'content/meetcomments.txt';
?>
</p></td>
</tr>
<tr>
<td><p>Regional Website</p></td>
<td><p>
<?php
$website = include 'content/website.txt';
echo stripslashes($website);?>

</p></td>
</tr>
<tr>
<td><p>Contact Details</p></td>
<td><p><?php
include 'content/contact.txt';
?></p></td>
</tr>
</table>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

<?php phpinfo(); ?>
is just a little script you should run. It tells you a lot about the php-configuration
see also: http://php.net/phpinfo
what's in content/website.txt?
bazpug
Forum Newbie
Posts: 8
Joined: Fri Oct 17, 2003 2:21 am

Post by bazpug »

magic_quotes_gpc On On
magic_quotes_runtime Off Off
magic_quotes_sybase Off Off

Thats the settings, I cant change these though.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

then you have to use stripslashes() on the userinput if you want the raw data
see also: http://php.net/manual/en/ref.info.php#i ... quotes-gpc
bazpug
Forum Newbie
Posts: 8
Joined: Fri Oct 17, 2003 2:21 am

Post by bazpug »

Where do I have to put the stripslashes() ?

:?:

Code: Select all

<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="meetlocation.txt">Meet Location
<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
  $filetext = htmlspecialchars ($filetext1);
  $fread = htmlspecialchars ($fread);
  $fwrite = htmlspecialchars ($fwrite);
  $fopen = htmlspecialchars ($fopen);

  ?>
    <?php  
   if ($_POST&#1111;"submit"]=="submit") &#123;  // begin if statement 
      if (@fwrite(@fopen($_POST&#1111;"write"],"wb"), $_POST&#1111;"filetext1"])) &#123; 
         echo "File write successful"; 
      &#125; else &#123; 
         echo "File write unsuccessful"; 
      &#125; 
   &#125; else &#123;                           //begin else block ?>
                                <input name="filetext1" type="text" value=" 
<?php echo htmlspecialchars(@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="meetlocation.txt">Meet Location
      <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 &#125;                            //end if statement?>
</form>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

if (@fwrite(@fopen($_POST["write"],"wb"), $_POST["filetext1"])) {
is this the data you want to show later on?
If so, I guess you have to use stripslashes on $_POST["filetext1"]
bazpug
Forum Newbie
Posts: 8
Joined: Fri Oct 17, 2003 2:21 am

Post by bazpug »

Yeah thats the data how do I use it there sorry its late at night and not making a lot of sense to me :S
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

if (@fwrite(@fopen($_POST["write"],"wb"), stripslashes($_POST["filetext1"]))) {
but this will not affect data that has already been added.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

bazpug
Forum Newbie
Posts: 8
Joined: Fri Oct 17, 2003 2:21 am

Post by bazpug »

Cheers for all the help, it now works a treat. I am off to buy a php book next week.

Cheers again

Baz
Post Reply