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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I still having problems with myt script. Can sombody help me?

Status
Not open for further replies.

Naits

Programmer
Oct 10, 2001
90
NO
This is a script for my webpage to add new cheats to my cheats section.

The problem is that when the php script writes to the html file the cheats that the user wants to is beeing on one line in the html file, but it is multiline when opens it. Also it is another problem when the php script writes to the html file it's cutting it off so its just about max350 - 400 characters long. It has an confirm screen and there it shows all cheats.
What have i done wrong??
Cold some body help me with making my script work??

Here is the hole script(if you want to try it you must make some folder namde:abc,def...):

<link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;../style.css&quot;>
<style>
<!--
body { background-color: black; color: white; font-family: arial;}

-->
</style>
<?

if (!isset($game_name) || !isset($cheat)) submit_cheat();
elseif ($confirm == &quot;yes&quot;) write_html($game_name,$nick,$email,$cheat);
else confirm($game_name,$nick,$email,$cheat);

function submit_cheat() {
?>
<form action=&quot;<? PHP_SELF ?>&quot; method=&quot;POST&quot;>
Name of game<font color=&quot;red&quot;>*</font>:<br>
<input type=&quot;text&quot; name=&quot;game_name&quot; size=&quot;20&quot;><br>
Your name/nickname:<br>
<input type=&quot;text&quot; name=&quot;nick&quot; size=&quot;20&quot;><br>
Your E-Mail:<br>
<input type=&quot;text&quot; name=&quot;email&quot; size=&quot;20&quot;><br>
Cheats you want to add<font color=&quot;red&quot;>*</font>:<br>
<textarea cols=&quot;70&quot; rows=&quot;20&quot; name=&quot;cheat&quot; wrap=&quot;hard&quot;></textarea><br>
<input type=&quot;submit&quot; value=&quot;Submit cheats&quot;>
<input type=&quot;reset&quot; value=&quot;Wipe out&quot;>
</form>
<hr>
<font color=&quot;red&quot;>* Must be filled out.</font>
<?
}

function confirm($game_name,$nick,$email,$cheat) {
$cheat = ereg_replace(&quot;\n&quot;, &quot;<br>\n&quot;, $cheat);
if (empty($nick)) $nick = &quot;Anonymous&quot;;
if (empty($email)) $email = &quot;Anonymous&quot;;

?>

<center><h1>CONFIRM</h1></center>
Game name:<br>
<? echo $game_name ?><br><br>

Your name/nickname:<br>
<? echo $nick ?><br><br>

Your E-Mail:<br>
<? echo $email ?><br><br>

The cheats you want to add:<br>
<pre>
<? echo $cheat ?><br>
</pre>
<hr>
<center>Is this right? If not, hit the back button and fix it.<br>
If it is right click <a href=&quot;subnew.php?confirm=yes&game_name=<? echo $game_name ?>&nick=<? echo $nick ?>&email=<? echo $email ?>&cheat=<? echo $cheat ?>&quot;>HERE</a></center>
<?
}

function write_html($game_name,$nick,$email,$cheat){
$a = $game_name{0};
if ($a == &quot;a&quot;) $folder = &quot;abc&quot;;
if ($a == &quot;b&quot;) $folder = &quot;abc&quot;;
if ($a == &quot;c&quot;) $folder = &quot;abc&quot;;
if ($a == &quot;d&quot;) $folder = &quot;def&quot;;
if ($a == &quot;e&quot;) $folder = &quot;def&quot;;
if ($a == &quot;f&quot;) $folder = &quot;def&quot;;
if ($a == &quot;g&quot;) $folder = &quot;ghi&quot;;
if ($a == &quot;h&quot;) $folder = &quot;ghi&quot;;
if ($a == &quot;i&quot;) $folder = &quot;ghi&quot;;
if ($a == &quot;j&quot;) $folder = &quot;jkl&quot;;
if ($a == &quot;k&quot;) $folder = &quot;jkl&quot;;
if ($a == &quot;l&quot;) $folder = &quot;jkl&quot;;
if ($a == &quot;m&quot;) $folder = &quot;mno&quot;;
if ($a == &quot;n&quot;) $folder = &quot;mno&quot;;
if ($a == &quot;o&quot;) $folder = &quot;mno&quot;;
if ($a == &quot;p&quot;) $folder = &quot;pqr&quot;;
if ($a == &quot;q&quot;) $folder = &quot;pqr&quot;;
if ($a == &quot;r&quot;) $folder = &quot;pqr&quot;;
if ($a == &quot;s&quot;) $folder = &quot;stu&quot;;
if ($a == &quot;t&quot;) $folder = &quot;stu&quot;;
if ($a == &quot;u&quot;) $folder = &quot;stu&quot;;
if ($a == &quot;v&quot;) $folder = &quot;vwx&quot;;
if ($a == &quot;w&quot;) $folder = &quot;vwx&quot;;
if ($a == &quot;x&quot;) $folder = &quot;vwx&quot;;
if ($a == &quot;y&quot;) $folder = &quot;yz&quot;;
if ($a == &quot;z&quot;) $folder = &quot;yz&quot;;
if ($a == &quot;A&quot;) $folder = &quot;abc&quot;;
if ($a == &quot;B&quot;) $folder = &quot;abc&quot;;
if ($a == &quot;C&quot;) $folder = &quot;abc&quot;;
if ($a == &quot;D&quot;) $folder = &quot;def&quot;;
if ($a == &quot;E&quot;) $folder = &quot;def&quot;;
if ($a == &quot;F&quot;) $folder = &quot;def&quot;;
if ($a == &quot;G&quot;) $folder = &quot;ghi&quot;;
if ($a == &quot;H&quot;) $folder = &quot;ghi&quot;;
if ($a == &quot;I&quot;) $folder = &quot;ghi&quot;;
if ($a == &quot;J&quot;) $folder = &quot;jkl&quot;;
if ($a == &quot;K&quot;) $folder = &quot;jkl&quot;;
if ($a == &quot;L&quot;) $folder = &quot;jkl&quot;;
if ($a == &quot;M&quot;) $folder = &quot;mno&quot;;
if ($a == &quot;N&quot;) $folder = &quot;mno&quot;;
if ($a == &quot;O&quot;) $folder = &quot;mno&quot;;
if ($a == &quot;P&quot;) $folder = &quot;pqr&quot;;
if ($a == &quot;Q&quot;) $folder = &quot;pqr&quot;;
if ($a == &quot;R&quot;) $folder = &quot;pqr&quot;;
if ($a == &quot;S&quot;) $folder = &quot;stu&quot;;
if ($a == &quot;T&quot;) $folder = &quot;stu&quot;;
if ($a == &quot;U&quot;) $folder = &quot;stu&quot;;
if ($a == &quot;V&quot;) $folder = &quot;vwx&quot;;
if ($a == &quot;W&quot;) $folder = &quot;vwx&quot;;
if ($a == &quot;X&quot;) $folder = &quot;vwx&quot;;
if ($a == &quot;Y&quot;) $folder = &quot;yz&quot;;
if ($a == &quot;Z&quot;) $folder = &quot;yz&quot;;

$html = &quot;<html>
<head>
<title>$game_name cheats</title>
</head>
<body>
<link rel='stylesheet' type='text/css' href='../../style.css'>
<style>
<!--
body { background-color: black; color: white; font-family: arial;}

-->
</style>
<center><font size=6>$game_name</font></center>
<a href='../$folder.php'><--Back</a>
<hr>
$cheat
<hr>
<font size=1>Submited by: $nick ($email)</font>
</body>
</html>&quot;;

$fp = fopen(&quot;$folder/$game_name.html&quot;, &quot;w+&quot;);
fwrite($fp, $html);
fclose($fp);
?>
<font size=7>Thanx!!</font><br><br><br>
<a href=&quot;<? echo $folder ?>.php&quot;><--Back</a>
<?
}
?>
 
Some things to try:

1. Try
Code:
str_replace
in place of
Code:
ereg_replace
, and escape your backslashes like this:
Code:
$cheat = str_replace(&quot;\\n&quot;, &quot;<br>\\n&quot;, $cheat);

2. You'll need to
Code:
stripslashes()
the fields POSTed to your script, since POSTed variables are automatically escaped. I'd also recommend
Code:
strip_tags
for security reasons.

3. Here's a function to simplify your folder name list:
Code:
function folder($name) {
	if ($handle = opendir(&quot;E:\\Path\\To\\Your\\Folders&quot;)) {
		while ($file = readdir($handle)) if (eregi($name{0},$file)) break;
		closedir($handle);
	}
	return $file;
}
Use it like
Code:
$folder = folder($name);

Hope this helps
-Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top