passing variables and displaying their values in form fields

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

Post Reply
User avatar
aerris
Forum Newbie
Posts: 5
Joined: Sun Feb 01, 2004 5:31 pm

passing variables and displaying their values in form fields

Post by aerris »

Hi, this is hopefully an easy one.
I can pass a value to a function:

Code: Select all

<FORM METHOD="post" ACTION="' . $_SERVER['PHP_SELF'] . '?editvenue=1; vid=' .$vid. '"><INPUT TYPE="submit" VALUE="Update"></FORM>
i know this works becuase i can see the value of vid in the url
but how would i get the value to display in the fields of an HTML form by default?
i have tried:

Code: Select all

<?php 
 elseif (isset($_GET['editvenue'])): // If the user wants to edit a venue
echo('

<form action="<?=$_SERVER['PHP_SELF']?>" method="post"> 
UPDATE VENUE<BR>
<p>Vid<br /> <BR>
<input type="text" name="vid" SIZE="4" VALUE="' . $vid . '"><br /><BR> 
<TABLE><TR><TD><FORM><input type="submit" name="updatevenue" value="Submit" /></FORM></TD><TD><FORM METHOD="LINK" ACTION="updatevenue.php"><INPUT TYPE="submit" VALUE="Cancel"></FORM></TD></TR></TABLE>
</p>');
?>
but it is not working.
is it something to do with this bit?:

Code: Select all

<?=$_SERVER['PHP_SELF']?>
btw: that last quote actually has a question mark greaterthan sign on the end of it but is not showing up on the forum

any help would be great
thanks!
hurdy gurdy
Forum Commoner
Posts: 40
Joined: Mon Jun 09, 2003 8:19 pm

Post by hurdy gurdy »

my guess would be to change this:

Code: Select all

(isset($_GET['editvenue'])):
to this:

Code: Select all

(isset($_POST['editvenue'])):
since your method is "POST" from the get-go...
correct me if I'm wrong. :)
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

i agree with hurdy gurdy, but you also need to add

Code: Select all

$vid = $_POST['vid'];
User avatar
aerris
Forum Newbie
Posts: 5
Joined: Sun Feb 01, 2004 5:31 pm

:D

Post by aerris »

ok i got it.

i changed it to this:

Code: Select all

elseif (isset($_GET['editvenue'])): // If the user wants to edit a venue
     $vid = $_GET['editvenue'];
and then this:

Code: Select all

<FORM METHOD="post" ACTION="' . $_SERVER['PHP_SELF'] . '?editvenue=' .$vid. '">
and that seems to work. :D
Post Reply