View Full Version : PHP form help
Rent-a-car
02-04-2008, 11:04 PM
hi well for my website i made an avatar and i want it to be used as an advertisement thing but the people who use it will be able to put their names on the avatar and i've done the code for it etc
i've got one page called index.php with a form in where someone can enter something into the box and i've got another page called avatar.php where i have the php code using $_GET to get the box name from the form and printing the text onto the image
what i want to do is stop it from redirecting to another page but have it so that when you click the button on the form the avatar appears below the form instead
the code for the index.php is here:
<html>
<body bgcolor="grey">
<center>
<form method="get" action="avatar.php">
Your Name: <input type="text" name="yourname"/>
<input type="submit" value="Get Avatar"/>
</form>
</body>
</html>
iUnknown
03-04-2008, 10:51 AM
hi well for my website i made an avatar and i want it to be used as an advertisement thing but the people who use it will be able to put their names on the avatar and i've done the code for it etc
i've got one page called index.php with a form in where someone can enter something into the box and i've got another page called avatar.php where i have the php code using $_GET to get the box name from the form and printing the text onto the image
what i want to do is stop it from redirecting to another page but have it so that when you click the button on the form the avatar appears below the form instead
the code for the index.php is here:
<html>
<body bgcolor="grey">
<center>
<form method="get" action="avatar.php">
Your Name: <input type="text" name="yourname"/>
<input type="submit" value="Get Avatar"/>
</form>
</body>
</html>
<html>
<body bgcolor="grey">
<center>
<form method="get" action="index.php">
Your Name: <input type="text" name="yourname"/>
<input type="submit" value="Get Avatar"/>
</form>
<? if($_GET["yourname"]){ ?>
<br />
avatar.php coding here
<? } ?>
</body>
</html>I think that's what you're after? When they submit the form, the page will refresh and it will show their avatar below. Note, I've put in a <br /> so that there will be a gap after the submit button. Put in your avatar.php coding where I said so that it does the code and I presume, if your coding works, shows their image :)
Rent-a-car
03-04-2008, 03:28 PM
Hey thanks for the help yes its the exact thing I want but I'm having a little trouble, because when I click the get avatar button it gives me an error saying headers have already been sent
iUnknown
03-04-2008, 05:48 PM
Hey thanks for the help yes its the exact thing I want but I'm having a little trouble, because when I click the get avatar button it gives me an error saying headers have already been sent
Try closing/reopening your browser? I think that might work - even though it sounds stupid.
Rent-a-car
03-04-2008, 06:48 PM
Warning: Cannot modify header information - headers already sent by (output started at /home/sjans/public_html/avatar/index.php:8) in /home/sjans/public_html/images/index.php on line 11
‰PNG ��� IHDR��^������WK��;IDATxœKHTQ™QQ0ŠRc,1 `zPP$Q cSQ‰F(!BEQRD[_k‘%.„‚ l5}Œ;98g€8pppp#1I�Hhzmz|EJul‹ cš‹uŽL:f-@Vj™‹Kb›@ƒ�'‚tl+w|�x 1#›ld�*M4!4f-C;€ҮnjŽvmtWU9jx›9Œ]KG/J<V7›mwU•�$8�énd!„!C2}&8f3^–buy=‘Ͷ‚m�œ1‘tw>€†#E#s|D@ֲ(œ1vƒ.LkAR=”žΝx_a3 f6�|=34…l)RœvGQۼ\ŠQᨮ˜Y€} W[w6›mq';W"66ˆRTI����IENDB`‚
and the browser thing didn't work
header("Content-type: image/png");
thats line 11
--ss--
03-04-2008, 07:20 PM
<html>
<body bgcolor="grey">
<center>
<?php
//Put all your GET variables here
if($_GET['yourname']) {
//Your GD libary Code goes here (The output)
}
else {
?>
<!-- The actual Form -->
<form method="get" action="avatar.php">
Your Name: <input type="text" name="yourname"/> <br />
<input type="submit" value="Get Avatar"/>
<!-- End of the Form -->
<?
}
?>
</center>
</body>
</html>
;).
Rent-a-car
03-04-2008, 08:24 PM
Okay i got past the headers already sent error with your code --ss-- but now I'm gettign another error saying that
"The image http://site.com/avatar/ cannot be displayed, because it contains errors."
Dentafrice
03-04-2008, 08:28 PM
You can't output data, then set headers.
Your going to need to make a seperate file with the GD info.
Example:
<?php
header("Content-type: image/png");
$text = $_GET["text"];
// GD stuff;
?>
and
<html>
<body bgcolor="grey">
<center>
<!-- The actual Form -->
<form method="get" action="avatar.php">
Your Name: <input type="text" name="yourname"/> <br />
<input type="submit" value="Get Avatar"/>
<!-- End of the Form -->
<img src="otherfile.php?text=<?php echo $_GET["yourname"]; ?>" />
</center>
</body>
</html>
Rent-a-car
03-04-2008, 08:38 PM
When I click Get Avatar it still goes onto the other page instead of refreshing the current page
Dentafrice
03-04-2008, 08:56 PM
well you saved it wrong.
Rent-a-car
03-04-2008, 09:37 PM
Nevermind I did it :P thanks :)
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2026 vBulletin Solutions Inc. All rights reserved.