chwebdesigns Posted June 2, 2007 Share Posted June 2, 2007 I am having a problem again with my PHP code. It is all working fine (thanks to some help off this forum) but when I try typing in a hyperlink or an image address I always get %22 on the end of it? Is there a way of stopping this from happening. It is a news page I have the problems with. Here is the code from the Add News Page: <?php $pass = md5($HTTP_POST_VARS['password'] ) ; if($HTTP_POST_VARS['submit']) { if($pass == 'password is here') { if(strstr($HTTP_POST_VARS['name'],"Select your name")) { echo "<h1 align=\"center\">You must select your name <a href=\"javascript:history.back(-1)\"> Go back</a></h1>"; exit; } if(!$HTTP_POST_VARS['title']) { echo "<h1 align=\"center\">You must enter a title <a href=\"javascript:history.back(-1)\"> Go back</a></h1>" ; exit; } if(!$HTTP_POST_VARS['news']) { echo "<h1 align=\"center\">You must enter some news <a href=\"javascript:history.back(-1)\"> Go back</a></h1>"; exit; } if(strstr($HTTP_POST_VARS['name'],"|")) { echo "<h1 align=\"center\">Name cannot contain the pipe symbol - |<a href=\"javascript:history.back(-1)\"> Go back </a></h1>"; exit; } if(strstr($HTTP_POST_VARS['title'],"|")) { echo "<h1 align=\"center\">Title cannot contain the pipe symbol - |<a href=\"javascript:history.back(-1)\"> Go back </a></h1>"; exit; } if(strstr($HTTP_POST_VARS['news'],"|")) { echo "<h1 align=\"center\">News cannot contain the pipe symbol - |<a href=\"javascript:history.back(-1)\"> Go back</a></h1>"; exit; } $fp = fopen('../newsadd.txt','a'); if(!$fp) { echo "<h1 align=\"center\">Error opening file! Please try again. If the error continues please contact the webmaster <a href=\"javascript:history.back(-1)\" Go back</a><br><a href=\"mailto:[email protected]?subject=php error UTKD code 101\"> E-mail the webmaster</a></h1>"; exit; } $line = "|" . date("d/m/y") . "|" . $HTTP_POST_VARS['name']; $line .= "|" . $HTTP_POST_VARS['title']; $line .= "|" . $HTTP_POST_VARS['news'] ; $line = str_replace("\r\n","<BR>",$line); $line .= "\r\n"; fwrite($fp, $line); if(!fclose($fp)) { echo "Error closing file! Please try again. If the error continues please contact the webmaster <a href=\"javascript:history.back(-1)\" Go back</a><br><a href=\"mailto:[email protected]?subject=php error UTKD code 102\"> E-mail the webmaster</a>"; exit; } echo "<h1>News item added</h1>" ; } else { echo "<h1>Bad Password</h1>"; } } ?> <FORM ACTION="<?=$PHP_SELF?>" METHOD="POST" NAME="newsentry"> <p align="center"><strong>Your name:</strong><BR> <select name="name" id="name"> <option selected title="select">Select your name</option> <option>Cheif Instrucor</option> <option>Instructor 1</option> <option>Instructor 3</option> <option>Webmaster</option> </select> </p> <p align="center"><strong>Title:</strong></p> <p align="center"><strong> <input name="title" type="text" id="title" value="" size="75" maxlength="100"> </strong><BR> <strong>The News:</strong><BR> <TEXTAREA NAME="news" COLS="75" ROWS="5"></TEXTAREA> <BR> <BR> <strong>News Password:</strong><BR> <INPUT TYPE="password" SIZE="30" NAME="password"> <BR> <INPUT TYPE="submit" NAME="submit" VALUE="Post it!"> <BR> </p> </FORM> And here is the code from the news page (which displays all the news) <?php $data = file('newsadd.txt'); $data = array_reverse($data); foreach($data as $element) { $element = trim($element); $pieces = explode("|", $element); echo "<h3 align=\"center\">" . $pieces[3] . "</h3>" . "" . "<i><h5 align=\"center\">Posted by " . $pieces[2] . " on " . $pieces[1] . "</b></i></h5><p align=\"center\">" . $pieces[4] . "<br><hr><br>" ; } ?> Thanks for your help From Cal Link to comment https://forums.phpfreaks.com/topic/53982-solved-22/ Share on other sites More sharing options...
per1os Posted June 2, 2007 Share Posted June 2, 2007 You can try trimming it www.php.net/trim The code you are using is pretty dated to. the $HTTP_POST_VARS hasn't been around since the early PHP4, any upgrade would kill your script. Link to comment https://forums.phpfreaks.com/topic/53982-solved-22/#findComment-266934 Share on other sites More sharing options...
chwebdesigns Posted June 2, 2007 Author Share Posted June 2, 2007 Thanks for that, I'll have to check to see if that works. If the PHP code works fine on my computers will it work the same on any viewers? I am extremley new to PHP and put together the code from different websites ect. As the code works fine, and it is just what I need. Also I don't have access to mySQL unfortunately, as the server won't allow connections to free sources and it costs way too much to have a mySQL account with them. Thanks from Cal Link to comment https://forums.phpfreaks.com/topic/53982-solved-22/#findComment-266978 Share on other sites More sharing options...
chocopi Posted June 2, 2007 Share Posted June 2, 2007 if you want a site that allows php and mysql for free you could use www.tripod.lycos.co.uk it can be a complete pain, but it is good for testing code and i think it uses some form of phpmyadmin Link to comment https://forums.phpfreaks.com/topic/53982-solved-22/#findComment-266987 Share on other sites More sharing options...
chwebdesigns Posted June 2, 2007 Author Share Posted June 2, 2007 Thanks for that site, I'll take a look Unfortunately, the trim function doesn't seem to work. Any other suggestions? Link to comment https://forums.phpfreaks.com/topic/53982-solved-22/#findComment-266988 Share on other sites More sharing options...
sprinkles Posted June 2, 2007 Share Posted June 2, 2007 I don't have time to look through your code at the moment, but %22 is the url entity for a double quote ("). See if a double quote is sneaking into your url somewhere. you can also use url_decode to change it back to a quote. Link to comment https://forums.phpfreaks.com/topic/53982-solved-22/#findComment-267000 Share on other sites More sharing options...
chwebdesigns Posted June 2, 2007 Author Share Posted June 2, 2007 Thanks for that "sprinkles", I was writing in parts <a href="website"> as I am more confident in writing HTML, and never realised it changes. Thanks! From Cal Link to comment https://forums.phpfreaks.com/topic/53982-solved-22/#findComment-267012 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.