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
defx
Forum Commoner
Posts: 36 Joined: Mon Feb 16, 2004 11:50 pm
Location: Florida, USA
Post
by defx » Sat Feb 21, 2004 12:04 pm
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
Illusionist
Forum Regular
Posts: 903 Joined: Mon Jan 12, 2004 9:32 pm
Post
by Illusionist » Sat Feb 21, 2004 12:07 pm
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\"\;";
defx
Forum Commoner
Posts: 36 Joined: Mon Feb 16, 2004 11:50 pm
Location: Florida, USA
Post
by defx » Sat Feb 21, 2004 12:10 pm
what exactly do you mean? could you apply it to a small portion of my script ?
Illusionist
Forum Regular
Posts: 903 Joined: Mon Jan 12, 2004 9:32 pm
Post
by Illusionist » Sat Feb 21, 2004 12:17 pm
$results = "<?php \$name = \"$n\"\; ?>";
defx
Forum Commoner
Posts: 36 Joined: Mon Feb 16, 2004 11:50 pm
Location: Florida, USA
Post
by defx » Sat Feb 21, 2004 12:19 pm
ah ty
defx
Forum Commoner
Posts: 36 Joined: Mon Feb 16, 2004 11:50 pm
Location: Florida, USA
Post
by defx » Sat Feb 21, 2004 12:23 pm
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
Illusionist
Forum Regular
Posts: 903 Joined: Mon Jan 12, 2004 9:32 pm
Post
by Illusionist » Sat Feb 21, 2004 12:30 pm
try putting a \ infront of the " before $n
Illusionist
Forum Regular
Posts: 903 Joined: Mon Jan 12, 2004 9:32 pm
Post
by Illusionist » Sat Feb 21, 2004 12:32 pm
and also a \ infront of $name
defx
Forum Commoner
Posts: 36 Joined: Mon Feb 16, 2004 11:50 pm
Location: Florida, USA
Post
by defx » Sat Feb 21, 2004 12:32 pm
i did, it just doesnt show up on the site for some reason
Illusionist
Forum Regular
Posts: 903 Joined: Mon Jan 12, 2004 9:32 pm
Post
by Illusionist » Sat Feb 21, 2004 12:34 pm
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"\;
?>";
?>
Last edited by
Illusionist on Sat Feb 21, 2004 12:37 pm, edited 3 times in total.
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Sat Feb 21, 2004 12:34 pm
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
Not sure why you're escaping the ;'s
defx
Forum Commoner
Posts: 36 Joined: Mon Feb 16, 2004 11:50 pm
Location: Florida, USA
Post
by defx » Sat Feb 21, 2004 12:36 pm
mark.. you're writing that info a file right? and it works ?
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Sat Feb 21, 2004 12:39 pm
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";
?>
Illusionist
Forum Regular
Posts: 903 Joined: Mon Jan 12, 2004 9:32 pm
Post
by Illusionist » Sat Feb 21, 2004 12:39 pm
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
Illusionist
Forum Regular
Posts: 903 Joined: Mon Jan 12, 2004 9:32 pm
Post
by Illusionist » Sat Feb 21, 2004 12:41 pm
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