Page 1 of 3

code not working, why :O

Posted: Sat Feb 21, 2004 12:04 pm
by defx

Code: Select all

<?php

		$p = isset($_GET['p'])?$_GET['p']:'';
		$user = isset($_GET['user'])?$_GET['user']:'';  
        
		if (empty($p)) { 
			echo ""; 
			
		} elseif (empty($user)) { 
			echo "";
		      
		} elseif ($p == "edit" && $user == "defx") { 
			$file = "defx.php";
			
		} elseif ($p == "submit") { 
			submit();
			
		} else {
			echo ("test");
		}
		
echo "<form method=POST action=profile.php?p=submit> <table border=0 width=282 cellspacing=0 cellpadding=0> <tr> <td valign=top width=132><font face=Verdana size=2>Name</font></td> <td valign=top width=148><font face=Verdana size=2><input type=text name=n size=20></font></td> </tr> <tr> <td valign=top width=132><font face=Verdana size=2> Age</font></td> <td valign=top width=148><font face=Verdana size=2> <input type=text name=a size=20></font></td> </tr> <tr> <td valign=top width=132><font face=Verdana size=2> Location</font></td> <td valign=top width=148><font face=Verdana size=2> <input type=text name=l size=20></font></td> </tr> <tr> <td valign=top width=132><font face=Verdana size=2>Favorite Map</font></td> <td valign=top width=148><font face=Verdana size=2> <input type=text name=fm size=20></font></td> </tr> <tr> <td valign=top width=132><font face=Verdana size=2> Achievements</font></td> <td valign=top width=148><font face=Verdana size=2> <input type=text name=ach size=20></font></td> </tr> <tr> <td valign=top width=132><font face=Verdana size=2> Past Clans</font></td> <td valign=top width=148><font face=Verdana size=2> <input type=text name=pc size=20></font></td> </tr> <tr> <td valign=top width=132><font face=Verdana size=2> League Experience</font></td> <td valign=top width=148><font face=Verdana size=2> <input type=text name=le size=20></font></td> </tr> <tr> <td valign=top width=132><font face=Verdana size=2> Resolution</font></td> <td valign=top width=148><font face=Verdana size=2> <input type=text name=r size=20></font></td> </tr> <tr> <td valign=top width=132><font face=Verdana size=2> Quote</font></td> <td valign=top width=148><font face=Verdana size=2> <input type=text name=q size=20></font></td> </tr> <tr> <td valign=top width=132><font face=Verdana size=2> Password</font></td> <td valign=top width=148><font face=Verdana size=2><input type=text name=pw size=20></font></td> </tr> <tr> <td valign=top width=132></td> <td valign=top width=148> <p align=right><font face=Verdana size=2><input type=submit value=Submit name=B1></font></p></td></tr></table></form>";

function submit()
{
extract($_POST);
$results = "<?php
$name = "$n";
$age = "$a";
$location = "$l";
$fmap = "$fm";
$achievements = "$ach";
$pastclan = "$pc";
$lexp = "$le";
$resolution = "$r";
$quote = "$q";
$p = "$pw";
?>";


$fp = fopen("$file", "w");
fwrite($fp, $results);
}
header ("Location: index.php?p=roster");
?>
all works fine until i submit, it doesnt write to the file

Posted: Sat Feb 21, 2004 12:07 pm
by Illusionist
if writing to a php file, and you want to keep all the variables like theya re you have to escape almost everything like this:

$tmp = "\$var1 = \"variable 1\"\;";

Posted: Sat Feb 21, 2004 12:10 pm
by defx
what exactly do you mean? could you apply it to a small portion of my script ?

Posted: Sat Feb 21, 2004 12:17 pm
by Illusionist
$results = "<?php \$name = \"$n\"\; ?>";

Posted: Sat Feb 21, 2004 12:19 pm
by defx
ah ty

Posted: Sat Feb 21, 2004 12:23 pm
by defx
eh nope, it still doesnt work for some reason

now i have this:

Code: Select all

function submit()
{
extract($_POST);
$results = "<?php
\$name = "$n"\;
\$age = "$a"\;
\$location = "$l"\;
\$fmap = "$fm"\;
\$achievements = "$ach"\;
\$pastclan = "$pc"\;
\$lexp = "$le"\;
\$resolution = "$r"\;
\$quote = "$q"\;
\$p = "$pw"\;
?>";
except there is a \ in front of $name

Posted: Sat Feb 21, 2004 12:30 pm
by Illusionist
try putting a \ infront of the " before $n

Posted: Sat Feb 21, 2004 12:32 pm
by Illusionist
and also a \ infront of $name

Posted: Sat Feb 21, 2004 12:32 pm
by defx
i did, it just doesnt show up on the site for some reason

Posted: Sat Feb 21, 2004 12:34 pm
by Illusionist
or, better yet, just use this:

Code: Select all

<?php

$result = "<?php
\$name = "$n"\;
\$age = "$a"\;
\$location = "$l"\;
\$fmap = "$fm"\;
\$achievements = "$ach"\;
\$pastclan ="$pc"\;
\$lexp = "$le"\;
\$resolution = "$r"\;
\$quote = "$q"\;
\$p = "$pw"\;
?>";

?>

Posted: Sat Feb 21, 2004 12:34 pm
by markl999

Code: Select all

<?php

$results = "<?php
\$name = "$n";
\$age = "$a";
\$location = "$l";
\$fmap = "$fm";
\$achievements = "$ach";
\$pastclan = "$pc";
\$lexp = "$le";
\$resolution = "$r";
\$quote = "$q";
\$p = "$pw";
?>";

?>
.. works for me :o Not sure why you're escaping the ;'s

Posted: Sat Feb 21, 2004 12:36 pm
by defx
mark.. you're writing that info a file right? and it works ?

Posted: Sat Feb 21, 2004 12:39 pm
by markl999
Yep, i assigned some test values to the vars and the following ends up in the file.

Code: Select all

<?php
$name = "one";
$age = "two";
$location = "three";
$fmap = "four";
$achievements = "five";
$pastclan = "six";
$lexp = "seven";
$resolution = "eight";
$quote = "nine";
$p = "ten";
?>

Posted: Sat Feb 21, 2004 12:39 pm
by Illusionist
Mark, try writing that to a file and it wont work if you don't escape the ;
defx, my code works i tested it before i posted it it just wasn't showing up right, so try mine now and it'll work

Posted: Sat Feb 21, 2004 12:41 pm
by Illusionist
And mark, your values aren't right anyways. It doesn't write $name to the file, it writes $n and same for all the others...

[edit] NEVER mind i didn't see where you said, the following shows up in the file