Define and submit value for variables in the page - HOW?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

User avatar
Tonkpils
New php-forum User
New php-forum User
Posts: 19
Joined: Tue Aug 19, 2003 6:11 am
Location: An Italian in Brusssels...

Define and submit value for variables in the page - HOW?

Postby Tonkpils » Tue Sep 02, 2003 3:05 am

Hello all,
which is the way to let a user choose an option on a page (check boxes), and with this define a value for a variable in the page itself?
I did a form, displayed with a statement to check is other values are set. Is so, a form is displayed. Here the user has two option in order to display stuff on the page. Seems that i don't get how to link the form to the variables values...
OF COURSE IF THERE ARE EXPEMLE AROUND JUST SEND ME THERE...
Thanks all...

toweter
New php-forum User
New php-forum User
Posts: 26
Joined: Sat Aug 30, 2003 9:04 am

Postby toweter » Tue Sep 02, 2003 3:24 am

You can access to the vars of your form with the following:

Code: Select all

$myvar = $_REQUEST['myvar'];

if your problem is only the checkbox, here a example how to:

Code: Select all

echo "<input type=checkbox name=myvar value=thevalueofmyvar>";

sigix
php-forum Active User
php-forum Active User
Posts: 364
Joined: Mon Jul 14, 2003 9:39 pm
Location: /Earth/Xion

Postby sigix » Tue Sep 02, 2003 6:49 am

you want to get value from user and then use the same value of variable in the same php page ?
( if yes you can do by setting the form action to the PHP_SELF and then track that variable/value according to get/post methods)

User avatar
Tonkpils
New php-forum User
New php-forum User
Posts: 19
Joined: Tue Aug 19, 2003 6:11 am
Location: An Italian in Brusssels...

Almost...

Postby Tonkpils » Wed Sep 03, 2003 12:49 am

I've almost did it, but now i have a problem displaying this string. How i can escape the carhacters?

Code: Select all

print ("<form name=\"status\" method=\"POST\" action=\"issues.php?pn=\".$_GET['pn'].\"\">");
This is the line where i get the error
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
How can i let the script accept

Code: Select all

.$_GET['pn'].
to read the variable?

sigix
php-forum Active User
php-forum Active User
Posts: 364
Joined: Mon Jul 14, 2003 9:39 pm
Location: /Earth/Xion

Postby sigix » Wed Sep 03, 2003 1:18 am

you can embed php in html like this

<form name="" method="post" action="<?php echo "issue.php?pn=".$_GET['pn']; ?> ">
...
...
</form>
will work neat

User avatar
Tonkpils
New php-forum User
New php-forum User
Posts: 19
Joined: Tue Aug 19, 2003 6:11 am
Location: An Italian in Brusssels...

Postby Tonkpils » Wed Sep 03, 2003 1:35 am

Is not a problem of embedding a piece of code. And more over, is not html pure, is displayed via the PHP parser, so there is something to do to let him read

Code: Select all

action="issues.php?pn=".$_GET['pn']."

User avatar
ruturajv
php-forum Super User
php-forum Super User
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India
Contact:

Re: Almost...

Postby ruturajv » Wed Sep 03, 2003 1:57 am

Tonkpils wrote:

Code: Select all

print ("<form name="status" method="POST" action="issues.php?pn=".$_GET['pn']."">");
This is the line where i get the error
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
How can i let the script accept

Code: Select all

.$_GET['pn'].
to read the variable?


Just see your above code you have escaped the charecter but have not closed the string

Code: Select all

print ("<form name="status" method="POST" action="issues.php?pn=" . $_GET['pn']. "">");


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google [Bot] and 1 guest